diff options
author | Iain Buclaw <ibuclaw@gcc.gnu.org> | 2018-10-28 19:51:47 +0000 |
---|---|---|
committer | Iain Buclaw <ibuclaw@gcc.gnu.org> | 2018-10-28 19:51:47 +0000 |
commit | b4c522fabd0df7be08882d2207df8b2765026110 (patch) | |
tree | b5ffc312b0a441c1ba24323152aec463fdbe5e9f /libphobos/src/etc | |
parent | 01ce9e31a02c8039d88e90f983735104417bf034 (diff) | |
download | gcc-b4c522fabd0df7be08882d2207df8b2765026110.zip gcc-b4c522fabd0df7be08882d2207df8b2765026110.tar.gz gcc-b4c522fabd0df7be08882d2207df8b2765026110.tar.bz2 |
Add D front-end, libphobos library, and D2 testsuite.
ChangeLog:
* Makefile.def (target_modules): Add libphobos.
(flags_to_pass): Add GDC, GDCFLAGS, GDC_FOR_TARGET and
GDCFLAGS_FOR_TARGET.
(dependencies): Make libphobos depend on libatomic, libbacktrace
configure, and zlib configure.
(language): Add language d.
* Makefile.in: Rebuild.
* Makefile.tpl (BUILD_EXPORTS): Add GDC and GDCFLAGS.
(HOST_EXPORTS): Add GDC.
(POSTSTAGE1_HOST_EXPORTS): Add GDC and GDC_FOR_BUILD.
(BASE_TARGET_EXPORTS): Add GDC.
(GDC_FOR_BUILD, GDC, GDCFLAGS): New variables.
(GDC_FOR_TARGET, GDC_FLAGS_FOR_TARGET): New variables.
(EXTRA_HOST_FLAGS): Add GDC.
(STAGE1_FLAGS_TO_PASS): Add GDC.
(EXTRA_TARGET_FLAGS): Add GDC and GDCFLAGS.
* config-ml.in: Treat GDC and GDCFLAGS like other compiler/flag
environment variables.
* configure: Rebuild.
* configure.ac: Add target-libphobos to target_libraries. Set and
substitute GDC_FOR_BUILD and GDC_FOR_TARGET.
config/ChangeLog:
* multi.m4: Set GDC.
gcc/ChangeLog:
* Makefile.in (tm_d_file_list, tm_d_include_list): New variables.
(TM_D_H, D_TARGET_DEF, D_TARGET_H, D_TARGET_OBJS): New variables.
(tm_d.h, cs-tm_d.h, default-d.o): New rules.
(d/d-target-hooks-def.h, s-d-target-hooks-def-h): New rules.
(s-tm-texi): Also check timestamp on d-target.def.
(generated_files): Add TM_D_H and d-target-hooks-def.h.
(build/genhooks.o): Also depend on D_TARGET_DEF.
* config.gcc (tm_d_file, d_target_objs, target_has_targetdm): New
variables.
* config/aarch64/aarch64-d.c: New file.
* config/aarch64/aarch64-linux.h (GNU_USER_TARGET_D_CRITSEC_SIZE):
Define.
* config/aarch64/aarch64-protos.h (aarch64_d_target_versions): New
prototype.
* config/aarch64/aarch64.h (TARGET_D_CPU_VERSIONS): Define.
* config/aarch64/t-aarch64 (aarch64-d.o): New rule.
* config/arm/arm-d.c: New file.
* config/arm/arm-protos.h (arm_d_target_versions): New prototype.
* config/arm/arm.h (TARGET_D_CPU_VERSIONS): Define.
* config/arm/linux-eabi.h (EXTRA_TARGET_D_OS_VERSIONS): Define.
* config/arm/t-arm (arm-d.o): New rule.
* config/default-d.c: New file.
* config/glibc-d.c: New file.
* config/gnu.h (GNU_USER_TARGET_D_OS_VERSIONS): Define.
* config/i386/i386-d.c: New file.
* config/i386/i386-protos.h (ix86_d_target_versions): New prototype.
* config/i386/i386.h (TARGET_D_CPU_VERSIONS): Define.
* config/i386/linux-common.h (EXTRA_TARGET_D_OS_VERSIONS): Define.
(GNU_USER_TARGET_D_CRITSEC_SIZE): Define.
* config/i386/t-i386 (i386-d.o): New rule.
* config/kfreebsd-gnu.h (GNU_USER_TARGET_D_OS_VERSIONS): Define.
* config/kopensolaris-gnu.h (GNU_USER_TARGET_D_OS_VERSIONS): Define.
* config/linux-android.h (ANDROID_TARGET_D_OS_VERSIONS): Define.
* config/linux.h (GNU_USER_TARGET_D_OS_VERSIONS): Define.
* config/mips/linux-common.h (EXTRA_TARGET_D_OS_VERSIONS): Define.
* config/mips/mips-d.c: New file.
* config/mips/mips-protos.h (mips_d_target_versions): New prototype.
* config/mips/mips.h (TARGET_D_CPU_VERSIONS): Define.
* config/mips/t-mips (mips-d.o): New rule.
* config/powerpcspe/linux.h (GNU_USER_TARGET_D_OS_VERSIONS): Define.
* config/powerpcspe/linux64.h (GNU_USER_TARGET_D_OS_VERSIONS): Define.
* config/powerpcspe/powerpcspe-d.c: New file.
* config/powerpcspe/powerpcspe-protos.h (rs6000_d_target_versions):
New prototype.
* config/powerpcspe/powerpcspe.c (rs6000_output_function_epilogue):
Support GNU D by using 0 as the language type.
* config/powerpcspe/powerpcspe.h (TARGET_D_CPU_VERSIONS): Define.
* config/powerpcspe/t-powerpcspe (powerpcspe-d.o): New rule.
* config/riscv/riscv-d.c: New file.
* config/riscv/riscv-protos.h (riscv_d_target_versions): New
prototype.
* config/riscv/riscv.h (TARGET_D_CPU_VERSIONS): Define.
* config/riscv/t-riscv (riscv-d.o): New rule.
* config/rs6000/linux.h (GNU_USER_TARGET_D_OS_VERSIONS): Define.
* config/rs6000/linux64.h (GNU_USER_TARGET_D_OS_VERSIONS): Define.
* config/rs6000/rs6000-d.c: New file.
* config/rs6000/rs6000-protos.h (rs6000_d_target_versions): New
prototype.
* config/rs6000/rs6000.c (rs6000_output_function_epilogue):
Support GNU D by using 0 as the language type.
* config/rs6000/rs6000.h (TARGET_D_CPU_VERSIONS): Define.
* config/rs6000/t-rs6000 (rs6000-d.o): New rule.
* config/s390/s390-d.c: New file.
* config/s390/s390-protos.h (s390_d_target_versions): New prototype.
* config/s390/s390.h (TARGET_D_CPU_VERSIONS): Define.
* config/s390/t-s390 (s390-d.o): New rule.
* config/sparc/sparc-d.c: New file.
* config/sparc/sparc-protos.h (sparc_d_target_versions): New
prototype.
* config/sparc/sparc.h (TARGET_D_CPU_VERSIONS): Define.
* config/sparc/t-sparc (sparc-d.o): New rule.
* config/t-glibc (glibc-d.o): New rule.
* configure: Regenerated.
* configure.ac (tm_d_file): New variable.
(tm_d_file_list, tm_d_include_list, d_target_objs): Add substitutes.
* doc/contrib.texi (Contributors): Add self for the D frontend.
* doc/frontends.texi (G++ and GCC): Mention D as a supported language.
* doc/install.texi (Configuration): Mention libphobos as an option for
--enable-shared. Mention d as an option for --enable-languages.
(Testing): Mention check-d as a target.
* doc/invoke.texi (Overall Options): Mention .d, .dd, and .di as file
name suffixes. Mention d as a -x option.
* doc/sourcebuild.texi (Top Level): Mention libphobos.
* doc/standards.texi (Standards): Add section on D language.
* doc/tm.texi: Regenerated.
* doc/tm.texi.in: Add @node for D language and ABI, and @hook for
TARGET_CPU_VERSIONS, TARGET_D_OS_VERSIONS, and TARGET_D_CRITSEC_SIZE.
* dwarf2out.c (is_dlang): New function.
(gen_compile_unit_die): Use DW_LANG_D for D.
(declare_in_namespace): Return module die for D, instead of adding
extra declarations into the namespace.
(gen_namespace_die): Generate DW_TAG_module for D.
(gen_decl_die): Handle CONST_DECLSs for D.
(dwarf2out_decl): Likewise.
(prune_unused_types_walk_local_classes): Handle DW_tag_interface_type.
(prune_unused_types_walk): Handle DW_tag_interface_type same as other
kinds of aggregates.
* gcc.c (default_compilers): Add entries for .d, .dd and .di.
* genhooks.c: Include d/d-target.def.
gcc/po/ChangeLog:
* EXCLUDES: Add sources from d/dmd.
gcc/testsuite/ChangeLog:
* gcc.misc-tests/help.exp: Add D to option descriptions check.
* gdc.dg/asan/asan.exp: New file.
* gdc.dg/asan/gdc272.d: New test.
* gdc.dg/compilable.d: New test.
* gdc.dg/dg.exp: New file.
* gdc.dg/gdc254.d: New test.
* gdc.dg/gdc260.d: New test.
* gdc.dg/gdc270a.d: New test.
* gdc.dg/gdc270b.d: New test.
* gdc.dg/gdc282.d: New test.
* gdc.dg/gdc283.d: New test.
* gdc.dg/imports/gdc170.d: New test.
* gdc.dg/imports/gdc231.d: New test.
* gdc.dg/imports/gdc239.d: New test.
* gdc.dg/imports/gdc241a.d: New test.
* gdc.dg/imports/gdc241b.d: New test.
* gdc.dg/imports/gdc251a.d: New test.
* gdc.dg/imports/gdc251b.d: New test.
* gdc.dg/imports/gdc253.d: New test.
* gdc.dg/imports/gdc254a.d: New test.
* gdc.dg/imports/gdc256.d: New test.
* gdc.dg/imports/gdc27.d: New test.
* gdc.dg/imports/gdcpkg256/package.d: New test.
* gdc.dg/imports/runnable.d: New test.
* gdc.dg/link.d: New test.
* gdc.dg/lto/lto.exp: New file.
* gdc.dg/lto/ltotests_0.d: New test.
* gdc.dg/lto/ltotests_1.d: New test.
* gdc.dg/runnable.d: New test.
* gdc.dg/simd.d: New test.
* gdc.test/gdc-test.exp: New file.
* lib/gdc-dg.exp: New file.
* lib/gdc.exp: New file.
libphobos/ChangeLog:
* Makefile.am: New file.
* Makefile.in: New file.
* acinclude.m4: New file.
* aclocal.m4: New file.
* config.h.in: New file.
* configure: New file.
* configure.ac: New file.
* d_rules.am: New file.
* libdruntime/Makefile.am: New file.
* libdruntime/Makefile.in: New file.
* libdruntime/__entrypoint.di: New file.
* libdruntime/__main.di: New file.
* libdruntime/gcc/attribute.d: New file.
* libdruntime/gcc/backtrace.d: New file.
* libdruntime/gcc/builtins.d: New file.
* libdruntime/gcc/config.d.in: New file.
* libdruntime/gcc/deh.d: New file.
* libdruntime/gcc/libbacktrace.d.in: New file.
* libdruntime/gcc/unwind/arm.d: New file.
* libdruntime/gcc/unwind/arm_common.d: New file.
* libdruntime/gcc/unwind/c6x.d: New file.
* libdruntime/gcc/unwind/generic.d: New file.
* libdruntime/gcc/unwind/package.d: New file.
* libdruntime/gcc/unwind/pe.d: New file.
* m4/autoconf.m4: New file.
* m4/druntime.m4: New file.
* m4/druntime/cpu.m4: New file.
* m4/druntime/libraries.m4: New file.
* m4/druntime/os.m4: New file.
* m4/gcc_support.m4: New file.
* m4/gdc.m4: New file.
* m4/libtool.m4: New file.
* src/Makefile.am: New file.
* src/Makefile.in: New file.
* src/libgphobos.spec.in: New file.
* testsuite/Makefile.am: New file.
* testsuite/Makefile.in: New file.
* testsuite/config/default.exp: New file.
* testsuite/lib/libphobos-dg.exp: New file.
* testsuite/lib/libphobos.exp: New file.
* testsuite/testsuite_flags.in: New file.
From-SVN: r265573
Diffstat (limited to 'libphobos/src/etc')
-rw-r--r-- | libphobos/src/etc/c/curl.d | 2336 | ||||
-rw-r--r-- | libphobos/src/etc/c/sqlite3.d | 2126 | ||||
-rw-r--r-- | libphobos/src/etc/c/zlib.d | 1788 |
3 files changed, 6250 insertions, 0 deletions
diff --git a/libphobos/src/etc/c/curl.d b/libphobos/src/etc/c/curl.d new file mode 100644 index 0000000..2cc588c --- /dev/null +++ b/libphobos/src/etc/c/curl.d @@ -0,0 +1,2336 @@ +/** + This is an interface to the libcurl library. + + Converted to D from curl headers by $(LINK2 http://www.digitalmars.com/d/2.0/htod.html, htod) and + cleaned up by Jonas Drewsen (jdrewsen) + + Windows x86 note: + A DMD compatible libcurl static library can be downloaded from the dlang.org + $(LINK2 http://dlang.org/download.html, download page). +*/ + +/* ************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + */ + +/** + * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at $(LINK http://curl.haxx.se/docs/copyright.html). + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +module etc.c.curl; + +import core.stdc.config; +import core.stdc.time; +import std.socket; + +// linux +import core.sys.posix.sys.socket; + +// +// LICENSE FROM CURL HEADERS +// + +/** This is the global package copyright */ +enum LIBCURL_COPYRIGHT = "1996 - 2010 Daniel Stenberg, <daniel@haxx.se>."; + +/** This is the version number of the libcurl package from which this header + file origins: */ +enum LIBCURL_VERSION = "7.21.4"; + +/** The numeric version number is also available "in parts" by using these + constants */ +enum LIBCURL_VERSION_MAJOR = 7; +/// ditto +enum LIBCURL_VERSION_MINOR = 21; +/// ditto +enum LIBCURL_VERSION_PATCH = 4; + +/** This is the numeric version of the libcurl version number, meant for easier + parsing and comparions by programs. The LIBCURL_VERSION_NUM define will + always follow this syntax: + + 0xXXYYZZ + + Where XX, YY and ZZ are the main version, release and patch numbers in + hexadecimal (using 8 bits each). All three numbers are always represented + using two digits. 1.2 would appear as "0x010200" while version 9.11.7 + appears as "0x090b07". + + This 6-digit (24 bits) hexadecimal number does not show pre-release number, + and it is always a greater number in a more recent release. It makes + comparisons with greater than and less than work. +*/ + +enum LIBCURL_VERSION_NUM = 0x071504; + +/** + * This is the date and time when the full source package was created. The + * timestamp is not stored in git, as the timestamp is properly set in the + * tarballs by the maketgz script. + * + * The format of the date should follow this template: + * + * "Mon Feb 12 11:35:33 UTC 2007" + */ +enum LIBCURL_TIMESTAMP = "Thu Feb 17 12:19:40 UTC 2011"; + +/** Data type definition of curl_off_t. + * + * jdrewsen - Always 64bit signed and that is what long is in D. + * + * Comment below is from curlbuild.h: + * + * NOTE 2: + * + * For any given platform/compiler curl_off_t must be typedef'ed to a + * 64-bit wide signed integral data type. The width of this data type + * must remain constant and independent of any possible large file + * support settings. + * + * As an exception to the above, curl_off_t shall be typedef'ed to a + * 32-bit wide signed integral data type if there is no 64-bit type. + */ +alias curl_off_t = long; + +/// +alias CURL = void; + +/// jdrewsen - Get socket alias from std.socket +alias curl_socket_t = socket_t; + +/// jdrewsen - Would like to get socket error constant from std.socket by it is private atm. +version (Windows) +{ + import core.sys.windows.windows, core.sys.windows.winsock2; + enum CURL_SOCKET_BAD = SOCKET_ERROR; +} +version (Posix) enum CURL_SOCKET_BAD = -1; + +/// +extern (C) struct curl_httppost +{ + curl_httppost *next; /** next entry in the list */ + char *name; /** pointer to allocated name */ + c_long namelength; /** length of name length */ + char *contents; /** pointer to allocated data contents */ + c_long contentslength; /** length of contents field */ + char *buffer; /** pointer to allocated buffer contents */ + c_long bufferlength; /** length of buffer field */ + char *contenttype; /** Content-Type */ + curl_slist *contentheader; /** list of extra headers for this form */ + curl_httppost *more; /** if one field name has more than one + file, this link should link to following + files */ + c_long flags; /** as defined below */ + char *showfilename; /** The file name to show. If not set, the + actual file name will be used (if this + is a file part) */ + void *userp; /** custom pointer used for + HTTPPOST_CALLBACK posts */ +} + +enum HTTPPOST_FILENAME = 1; /** specified content is a file name */ +enum HTTPPOST_READFILE = 2; /** specified content is a file name */ +enum HTTPPOST_PTRNAME = 4; /** name is only stored pointer + do not free in formfree */ +enum HTTPPOST_PTRCONTENTS = 8; /** contents is only stored pointer + do not free in formfree */ +enum HTTPPOST_BUFFER = 16; /** upload file from buffer */ +enum HTTPPOST_PTRBUFFER = 32; /** upload file from pointer contents */ +enum HTTPPOST_CALLBACK = 64; /** upload file contents by using the + regular read callback to get the data + and pass the given pointer as custom + pointer */ + +/// +alias curl_progress_callback = int function(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow); + +/** Tests have proven that 20K is a very bad buffer size for uploads on + Windows, while 16K for some odd reason performed a lot better. + We do the ifndef check to allow this value to easier be changed at build + time for those who feel adventurous. The practical minimum is about + 400 bytes since libcurl uses a buffer of this size as a scratch area + (unrelated to network send operations). */ +enum CURL_MAX_WRITE_SIZE = 16_384; + +/** The only reason to have a max limit for this is to avoid the risk of a bad + server feeding libcurl with a never-ending header that will cause reallocs + infinitely */ +enum CURL_MAX_HTTP_HEADER = (100*1024); + + +/** This is a magic return code for the write callback that, when returned, + will signal libcurl to pause receiving on the current transfer. */ +enum CURL_WRITEFUNC_PAUSE = 0x10000001; + +/// +alias curl_write_callback = size_t function(char *buffer, size_t size, size_t nitems, void *outstream); + +/** enumeration of file types */ +enum CurlFileType { + file, /// + directory, /// + symlink, /// + device_block, /// + device_char, /// + namedpipe, /// + socket, /// + door, /// + unknown /** is possible only on Sun Solaris now */ +} + +/// +alias curlfiletype = int; + +/// +enum CurlFInfoFlagKnown { + filename = 1, /// + filetype = 2, /// + time = 4, /// + perm = 8, /// + uid = 16, /// + gid = 32, /// + size = 64, /// + hlinkcount = 128 /// +} + +/** Content of this structure depends on information which is known and is + achievable (e.g. by FTP LIST parsing). Please see the url_easy_setopt(3) man + page for callbacks returning this structure -- some fields are mandatory, + some others are optional. The FLAG field has special meaning. */ + + +/** If some of these fields is not NULL, it is a pointer to b_data. */ +extern (C) struct _N2 +{ + char *time; /// + char *perm; /// + char *user; /// + char *group; /// + char *target; /** pointer to the target filename of a symlink */ +} + +/** Content of this structure depends on information which is known and is + achievable (e.g. by FTP LIST parsing). Please see the url_easy_setopt(3) man + page for callbacks returning this structure -- some fields are mandatory, + some others are optional. The FLAG field has special meaning. */ +extern (C) struct curl_fileinfo +{ + char *filename; /// + curlfiletype filetype; /// + time_t time; /// + uint perm; /// + int uid; /// + int gid; /// + curl_off_t size; /// + c_long hardlinks; /// + _N2 strings; /// + uint flags; /// + char *b_data; /// + size_t b_size; /// + size_t b_used; /// +} + +/** return codes for CURLOPT_CHUNK_BGN_FUNCTION */ +enum CurlChunkBgnFunc { + ok = 0, /// + fail = 1, /** tell the lib to end the task */ + skip = 2 /** skip this chunk over */ +} + +/** if splitting of data transfer is enabled, this callback is called before + download of an individual chunk started. Note that parameter "remains" works + only for FTP wildcard downloading (for now), otherwise is not used */ +alias curl_chunk_bgn_callback = c_long function(void *transfer_info, void *ptr, int remains); + +/** return codes for CURLOPT_CHUNK_END_FUNCTION */ +enum CurlChunkEndFunc { + ok = 0, /// + fail = 1, /// +} +/** If splitting of data transfer is enabled this callback is called after + download of an individual chunk finished. + Note! After this callback was set then it have to be called FOR ALL chunks. + Even if downloading of this chunk was skipped in CHUNK_BGN_FUNC. + This is the reason why we don't need "transfer_info" parameter in this + callback and we are not interested in "remains" parameter too. */ +alias curl_chunk_end_callback = c_long function(void *ptr); + +/** return codes for FNMATCHFUNCTION */ +enum CurlFnMAtchFunc { + match = 0, /// + nomatch = 1, /// + fail = 2 /// +} + +/** callback type for wildcard downloading pattern matching. If the + string matches the pattern, return CURL_FNMATCHFUNC_MATCH value, etc. */ +alias curl_fnmatch_callback = int function(void *ptr, in char *pattern, in char *string); + +/// seek whence... +enum CurlSeekPos { + set, /// + current, /// + end /// +} + +/** These are the return codes for the seek callbacks */ +enum CurlSeek { + ok, /// + fail, /** fail the entire transfer */ + cantseek /** tell libcurl seeking can't be done, so + libcurl might try other means instead */ +} + +/// +alias curl_seek_callback = int function(void *instream, curl_off_t offset, int origin); + +/// +enum CurlReadFunc { + /** This is a return code for the read callback that, when returned, will + signal libcurl to immediately abort the current transfer. */ + abort = 0x10000000, + + /** This is a return code for the read callback that, when returned, + will const signal libcurl to pause sending data on the current + transfer. */ + pause = 0x10000001 +} + +/// +alias curl_read_callback = size_t function(char *buffer, size_t size, size_t nitems, void *instream); + +/// +enum CurlSockType { + ipcxn, /** socket created for a specific IP connection */ + last /** never use */ +} +/// +alias curlsocktype = int; + +/// +alias curl_sockopt_callback = int function(void *clientp, curl_socket_t curlfd, curlsocktype purpose); + +/** addrlen was a socklen_t type before 7.18.0 but it turned really + ugly and painful on the systems that lack this type */ +extern (C) struct curl_sockaddr +{ + int family; /// + int socktype; /// + int protocol; /// + uint addrlen; /** addrlen was a socklen_t type before 7.18.0 but it + turned really ugly and painful on the systems that + lack this type */ + sockaddr addr; /// +} + +/// +alias curl_opensocket_callback = curl_socket_t function(void *clientp, curlsocktype purpose, curl_sockaddr *address); + +/// +enum CurlIoError +{ + ok, /** I/O operation successful */ + unknowncmd, /** command was unknown to callback */ + failrestart, /** failed to restart the read */ + last /** never use */ +} +/// +alias curlioerr = int; + +/// +enum CurlIoCmd { + nop, /** command was unknown to callback */ + restartread, /** failed to restart the read */ + last, /** never use */ +} +/// +alias curliocmd = int; + +/// +alias curl_ioctl_callback = curlioerr function(CURL *handle, int cmd, void *clientp); + +/** + * The following typedef's are signatures of malloc, free, realloc, strdup and + * calloc respectively. Function pointers of these types can be passed to the + * curl_global_init_mem() function to set user defined memory management + * callback routines. + */ +alias curl_malloc_callback = void* function(size_t size); +/// ditto +alias curl_free_callback = void function(void *ptr); +/// ditto +alias curl_realloc_callback = void* function(void *ptr, size_t size); +/// ditto +alias curl_strdup_callback = char * function(in char *str); +/// ditto +alias curl_calloc_callback = void* function(size_t nmemb, size_t size); + +/** the kind of data that is passed to information_callback*/ +enum CurlCallbackInfo { + text, /// + header_in, /// + header_out, /// + data_in, /// + data_out, /// + ssl_data_in, /// + ssl_data_out, /// + end /// +} +/// +alias curl_infotype = int; + +/// +alias curl_debug_callback = + int function(CURL *handle, /** the handle/transfer this concerns */ + curl_infotype type, /** what kind of data */ + char *data, /** points to the data */ + size_t size, /** size of the data pointed to */ + void *userptr /** whatever the user please */ + ); + +/** All possible error codes from all sorts of curl functions. Future versions + may return other values, stay prepared. + + Always add new return codes last. Never *EVER* remove any. The return + codes must remain the same! + */ +enum CurlError +{ + ok, /// + unsupported_protocol, /** 1 */ + failed_init, /** 2 */ + url_malformat, /** 3 */ + not_built_in, /** 4 - [was obsoleted in August 2007 for + 7.17.0, reused in April 2011 for 7.21.5] */ + couldnt_resolve_proxy, /** 5 */ + couldnt_resolve_host, /** 6 */ + couldnt_connect, /** 7 */ + ftp_weird_server_reply, /** 8 */ + remote_access_denied, /** 9 a service was denied by the server + due to lack of access - when login fails + this is not returned. */ + obsolete10, /** 10 - NOT USED */ + ftp_weird_pass_reply, /** 11 */ + obsolete12, /** 12 - NOT USED */ + ftp_weird_pasv_reply, /** 13 */ + ftp_weird_227_format, /** 14 */ + ftp_cant_get_host, /** 15 */ + obsolete16, /** 16 - NOT USED */ + ftp_couldnt_set_type, /** 17 */ + partial_file, /** 18 */ + ftp_couldnt_retr_file, /** 19 */ + obsolete20, /** 20 - NOT USED */ + quote_error, /** 21 - quote command failure */ + http_returned_error, /** 22 */ + write_error, /** 23 */ + obsolete24, /** 24 - NOT USED */ + upload_failed, /** 25 - failed upload "command" */ + read_error, /** 26 - couldn't open/read from file */ + out_of_memory, /** 27 */ + /** Note: CURLE_OUT_OF_MEMORY may sometimes indicate a conversion error + instead of a memory allocation error if CURL_DOES_CONVERSIONS + is defined + */ + operation_timedout, /** 28 - the timeout time was reached */ + obsolete29, /** 29 - NOT USED */ + ftp_port_failed, /** 30 - FTP PORT operation failed */ + ftp_couldnt_use_rest, /** 31 - the REST command failed */ + obsolete32, /** 32 - NOT USED */ + range_error, /** 33 - RANGE "command" didn't work */ + http_post_error, /** 34 */ + ssl_connect_error, /** 35 - wrong when connecting with SSL */ + bad_download_resume, /** 36 - couldn't resume download */ + file_couldnt_read_file, /** 37 */ + ldap_cannot_bind, /** 38 */ + ldap_search_failed, /** 39 */ + obsolete40, /** 40 - NOT USED */ + function_not_found, /** 41 */ + aborted_by_callback, /** 42 */ + bad_function_argument, /** 43 */ + obsolete44, /** 44 - NOT USED */ + interface_failed, /** 45 - CURLOPT_INTERFACE failed */ + obsolete46, /** 46 - NOT USED */ + too_many_redirects, /** 47 - catch endless re-direct loops */ + unknown_option, /** 48 - User specified an unknown option */ + telnet_option_syntax, /** 49 - Malformed telnet option */ + obsolete50, /** 50 - NOT USED */ + peer_failed_verification, /** 51 - peer's certificate or fingerprint + wasn't verified fine */ + got_nothing, /** 52 - when this is a specific error */ + ssl_engine_notfound, /** 53 - SSL crypto engine not found */ + ssl_engine_setfailed, /** 54 - can not set SSL crypto engine as default */ + send_error, /** 55 - failed sending network data */ + recv_error, /** 56 - failure in receiving network data */ + obsolete57, /** 57 - NOT IN USE */ + ssl_certproblem, /** 58 - problem with the local certificate */ + ssl_cipher, /** 59 - couldn't use specified cipher */ + ssl_cacert, /** 60 - problem with the CA cert (path?) */ + bad_content_encoding, /** 61 - Unrecognized transfer encoding */ + ldap_invalid_url, /** 62 - Invalid LDAP URL */ + filesize_exceeded, /** 63 - Maximum file size exceeded */ + use_ssl_failed, /** 64 - Requested FTP SSL level failed */ + send_fail_rewind, /** 65 - Sending the data requires a rewind that failed */ + ssl_engine_initfailed, /** 66 - failed to initialise ENGINE */ + login_denied, /** 67 - user, password or similar was not accepted and we failed to login */ + tftp_notfound, /** 68 - file not found on server */ + tftp_perm, /** 69 - permission problem on server */ + remote_disk_full, /** 70 - out of disk space on server */ + tftp_illegal, /** 71 - Illegal TFTP operation */ + tftp_unknownid, /** 72 - Unknown transfer ID */ + remote_file_exists, /** 73 - File already exists */ + tftp_nosuchuser, /** 74 - No such user */ + conv_failed, /** 75 - conversion failed */ + conv_reqd, /** 76 - caller must register conversion + callbacks using curl_easy_setopt options + CURLOPT_CONV_FROM_NETWORK_FUNCTION, + CURLOPT_CONV_TO_NETWORK_FUNCTION, and + CURLOPT_CONV_FROM_UTF8_FUNCTION */ + ssl_cacert_badfile, /** 77 - could not load CACERT file, missing or wrong format */ + remote_file_not_found, /** 78 - remote file not found */ + ssh, /** 79 - error from the SSH layer, somewhat + generic so the error message will be of + interest when this has happened */ + ssl_shutdown_failed, /** 80 - Failed to shut down the SSL connection */ + again, /** 81 - socket is not ready for send/recv, + wait till it's ready and try again (Added + in 7.18.2) */ + ssl_crl_badfile, /** 82 - could not load CRL file, missing or wrong format (Added in 7.19.0) */ + ssl_issuer_error, /** 83 - Issuer check failed. (Added in 7.19.0) */ + ftp_pret_failed, /** 84 - a PRET command failed */ + rtsp_cseq_error, /** 85 - mismatch of RTSP CSeq numbers */ + rtsp_session_error, /** 86 - mismatch of RTSP Session Identifiers */ + ftp_bad_file_list, /** 87 - unable to parse FTP file list */ + chunk_failed, /** 88 - chunk callback reported error */ + curl_last /** never use! */ +} +/// +alias CURLcode = int; + +/** This prototype applies to all conversion callbacks */ +alias curl_conv_callback = CURLcode function(char *buffer, size_t length); + +/** actually an OpenSSL SSL_CTX */ +alias curl_ssl_ctx_callback = + CURLcode function(CURL *curl, /** easy handle */ + void *ssl_ctx, /** actually an OpenSSL SSL_CTX */ + void *userptr + ); + +/// +enum CurlProxy { + http, /** added in 7.10, new in 7.19.4 default is to use CONNECT HTTP/1.1 */ + http_1_0, /** added in 7.19.4, force to use CONNECT HTTP/1.0 */ + socks4 = 4, /** support added in 7.15.2, enum existed already in 7.10 */ + socks5 = 5, /** added in 7.10 */ + socks4a = 6, /** added in 7.18.0 */ + socks5_hostname =7 /** Use the SOCKS5 protocol but pass along the + host name rather than the IP address. added + in 7.18.0 */ +} +/// +alias curl_proxytype = int; + +/// +enum CurlAuth : long { + none = 0, + basic = 1, /** Basic (default) */ + digest = 2, /** Digest */ + gssnegotiate = 4, /** GSS-Negotiate */ + ntlm = 8, /** NTLM */ + digest_ie = 16, /** Digest with IE flavour */ + only = 2_147_483_648, /** used together with a single other + type to force no auth or just that + single type */ + any = -17, /* (~CURLAUTH_DIGEST_IE) */ /** all fine types set */ + anysafe = -18 /* (~(CURLAUTH_BASIC|CURLAUTH_DIGEST_IE)) */ /// +} + +/// +enum CurlSshAuth { + any = -1, /** all types supported by the server */ + none = 0, /** none allowed, silly but complete */ + publickey = 1, /** public/private key files */ + password = 2, /** password */ + host = 4, /** host key files */ + keyboard = 8, /** keyboard interactive */ + default_ = -1 // CURLSSH_AUTH_ANY; +} +/// +enum CURL_ERROR_SIZE = 256; +/** points to a zero-terminated string encoded with base64 + if len is zero, otherwise to the "raw" data */ +enum CurlKHType +{ + unknown, /// + rsa1, /// + rsa, /// + dss /// +} +/// +extern (C) struct curl_khkey +{ + const(char) *key; /** points to a zero-terminated string encoded with base64 + if len is zero, otherwise to the "raw" data */ + size_t len; /// + CurlKHType keytype; /// +} + +/** this is the set of return values expected from the curl_sshkeycallback + callback */ +enum CurlKHStat { + fine_add_to_file, /// + fine, /// + reject, /** reject the connection, return an error */ + defer, /** do not accept it, but we can't answer right now so + this causes a CURLE_DEFER error but otherwise the + connection will be left intact etc */ + last /** not for use, only a marker for last-in-list */ +} + +/** this is the set of status codes pass in to the callback */ +enum CurlKHMatch { + ok, /** match */ + mismatch, /** host found, key mismatch! */ + missing, /** no matching host/key found */ + last /** not for use, only a marker for last-in-list */ +} + +/// +alias curl_sshkeycallback = + int function(CURL *easy, /** easy handle */ + curl_khkey *knownkey, /** known */ + curl_khkey *foundkey, /** found */ + CurlKHMatch m, /** libcurl's view on the keys */ + void *clientp /** custom pointer passed from app */ + ); + +/** parameter for the CURLOPT_USE_SSL option */ +enum CurlUseSSL { + none, /** do not attempt to use SSL */ + tryssl, /** try using SSL, proceed anyway otherwise */ + control, /** SSL for the control connection or fail */ + all, /** SSL for all communication or fail */ + last /** not an option, never use */ +} +/// +alias curl_usessl = int; + +/** parameter for the CURLOPT_FTP_SSL_CCC option */ +enum CurlFtpSSL { + ccc_none, /** do not send CCC */ + ccc_passive, /** Let the server initiate the shutdown */ + ccc_active, /** Initiate the shutdown */ + ccc_last /** not an option, never use */ +} +/// +alias curl_ftpccc = int; + +/** parameter for the CURLOPT_FTPSSLAUTH option */ +enum CurlFtpAuth { + defaultauth, /** let libcurl decide */ + ssl, /** use "AUTH SSL" */ + tls, /** use "AUTH TLS" */ + last /** not an option, never use */ +} +/// +alias curl_ftpauth = int; + +/** parameter for the CURLOPT_FTP_CREATE_MISSING_DIRS option */ +enum CurlFtp { + create_dir_none, /** do NOT create missing dirs! */ + create_dir, /** (FTP/SFTP) if CWD fails, try MKD and then CWD again if MKD + succeeded, for SFTP this does similar magic */ + create_dir_retry, /** (FTP only) if CWD fails, try MKD and then CWD again even if MKD + failed! */ + create_dir_last /** not an option, never use */ +} +/// +alias curl_ftpcreatedir = int; + +/** parameter for the CURLOPT_FTP_FILEMETHOD option */ +enum CurlFtpMethod { + defaultmethod, /** let libcurl pick */ + multicwd, /** single CWD operation for each path part */ + nocwd, /** no CWD at all */ + singlecwd, /** one CWD to full dir, then work on file */ + last /** not an option, never use */ +} +/// +alias curl_ftpmethod = int; + +/** CURLPROTO_ defines are for the CURLOPT_*PROTOCOLS options */ +enum CurlProto { + http = 1, /// + https = 2, /// + ftp = 4, /// + ftps = 8, /// + scp = 16, /// + sftp = 32, /// + telnet = 64, /// + ldap = 128, /// + ldaps = 256, /// + dict = 512, /// + file = 1024, /// + tftp = 2048, /// + imap = 4096, /// + imaps = 8192, /// + pop3 = 16_384, /// + pop3s = 32_768, /// + smtp = 65_536, /// + smtps = 131_072, /// + rtsp = 262_144, /// + rtmp = 524_288, /// + rtmpt = 1_048_576, /// + rtmpe = 2_097_152, /// + rtmpte = 4_194_304, /// + rtmps = 8_388_608, /// + rtmpts = 16_777_216, /// + gopher = 33_554_432, /// + all = -1 /** enable everything */ +} + +/** long may be 32 or 64 bits, but we should never depend on anything else + but 32 */ +enum CURLOPTTYPE_LONG = 0; +/// ditto +enum CURLOPTTYPE_OBJECTPOINT = 10_000; +/// ditto +enum CURLOPTTYPE_FUNCTIONPOINT = 20_000; + +/// ditto +enum CURLOPTTYPE_OFF_T = 30_000; +/** name is uppercase CURLOPT_$(LT)name$(GT), + type is one of the defined CURLOPTTYPE_$(LT)type$(GT) + number is unique identifier */ + +/** The macro "##" is ISO C, we assume pre-ISO C doesn't support it. */ +alias LONG = CURLOPTTYPE_LONG; +/// ditto +alias OBJECTPOINT = CURLOPTTYPE_OBJECTPOINT; +/// ditto +alias FUNCTIONPOINT = CURLOPTTYPE_FUNCTIONPOINT; + +/// ditto +alias OFF_T = CURLOPTTYPE_OFF_T; + +/// +enum CurlOption { + /** This is the FILE * or void * the regular output should be written to. */ + file = 10_001, + /** The full URL to get/put */ + url, + /** Port number to connect to, if other than default. */ + port = 3, + /** Name of proxy to use. */ + proxy = 10_004, + /** "name:password" to use when fetching. */ + userpwd, + /** "name:password" to use with proxy. */ + proxyuserpwd, + /** Range to get, specified as an ASCII string. */ + range, + /** not used */ + + /** Specified file stream to upload from (use as input): */ + infile = 10_009, + /** Buffer to receive error messages in, must be at least CURL_ERROR_SIZE + * bytes big. If this is not used, error messages go to stderr instead: */ + errorbuffer, + /** Function that will be called to store the output (instead of fwrite). The + * parameters will use fwrite() syntax, make sure to follow them. */ + writefunction = 20_011, + /** Function that will be called to read the input (instead of fread). The + * parameters will use fread() syntax, make sure to follow them. */ + readfunction, + /** Time-out the read operation after this amount of seconds */ + timeout = 13, + /** If the CURLOPT_INFILE is used, this can be used to inform libcurl about + * how large the file being sent really is. That allows better error + * checking and better verifies that the upload was successful. -1 means + * unknown size. + * + * For large file support, there is also a _LARGE version of the key + * which takes an off_t type, allowing platforms with larger off_t + * sizes to handle larger files. See below for INFILESIZE_LARGE. + */ + infilesize, + /** POST static input fields. */ + postfields = 10_015, + /** Set the referrer page (needed by some CGIs) */ + referer, + /** Set the FTP PORT string (interface name, named or numerical IP address) + Use i.e '-' to use default address. */ + ftpport, + /** Set the User-Agent string (examined by some CGIs) */ + useragent, + /** If the download receives less than "low speed limit" bytes/second + * during "low speed time" seconds, the operations is aborted. + * You could i.e if you have a pretty high speed connection, abort if + * it is less than 2000 bytes/sec during 20 seconds. + */ + + /** Set the "low speed limit" */ + low_speed_limit = 19, + /** Set the "low speed time" */ + low_speed_time, + /** Set the continuation offset. + * + * Note there is also a _LARGE version of this key which uses + * off_t types, allowing for large file offsets on platforms which + * use larger-than-32-bit off_t's. Look below for RESUME_FROM_LARGE. + */ + resume_from, + /** Set cookie in request: */ + cookie = 10_022, + /** This points to a linked list of headers, struct curl_slist kind */ + httpheader, + /** This points to a linked list of post entries, struct curl_httppost */ + httppost, + /** name of the file keeping your private SSL-certificate */ + sslcert, + /** password for the SSL or SSH private key */ + keypasswd, + /** send TYPE parameter? */ + crlf = 27, + /** send linked-list of QUOTE commands */ + quote = 10_028, + /** send FILE * or void * to store headers to, if you use a callback it + is simply passed to the callback unmodified */ + writeheader, + /** point to a file to read the initial cookies from, also enables + "cookie awareness" */ + cookiefile = 10_031, + /** What version to specifically try to use. + See CURL_SSLVERSION defines below. */ + sslversion = 32, + /** What kind of HTTP time condition to use, see defines */ + timecondition, + /** Time to use with the above condition. Specified in number of seconds + since 1 Jan 1970 */ + timevalue, + /* 35 = OBSOLETE */ + + /** Custom request, for customizing the get command like + HTTP: DELETE, TRACE and others + FTP: to use a different list command + */ + customrequest = 10_036, + /** HTTP request, for odd commands like DELETE, TRACE and others */ + stderr, + /* 38 is not used */ + + /** send linked-list of post-transfer QUOTE commands */ + postquote = 10_039, + /** Pass a pointer to string of the output using full variable-replacement + as described elsewhere. */ + writeinfo, + verbose = 41, /** talk a lot */ + header, /** throw the header out too */ + noprogress, /** shut off the progress meter */ + nobody, /** use HEAD to get http document */ + failonerror, /** no output on http error codes >= 300 */ + upload, /** this is an upload */ + post, /** HTTP POST method */ + dirlistonly, /** return bare names when listing directories */ + append = 50, /** Append instead of overwrite on upload! */ + /** Specify whether to read the user+password from the .netrc or the URL. + * This must be one of the CURL_NETRC_* enums below. */ + netrc, + followlocation, /** use Location: Luke! */ + transfertext, /** transfer data in text/ASCII format */ + put, /** HTTP PUT */ + /* 55 = OBSOLETE */ + + /** Function that will be called instead of the internal progress display + * function. This function should be defined as the curl_progress_callback + * prototype defines. */ + progressfunction = 20_056, + /** Data passed to the progress callback */ + progressdata = 10_057, + /** We want the referrer field set automatically when following locations */ + autoreferer = 58, + /** Port of the proxy, can be set in the proxy string as well with: + "[host]:[port]" */ + proxyport, + /** size of the POST input data, if strlen() is not good to use */ + postfieldsize, + /** tunnel non-http operations through a HTTP proxy */ + httpproxytunnel, + /** Set the interface string to use as outgoing network interface */ + intrface = 10_062, + /** Set the krb4/5 security level, this also enables krb4/5 awareness. This + * is a string, 'clear', 'safe', 'confidential' or 'private'. If the string + * is set but doesn't match one of these, 'private' will be used. */ + krblevel, + /** Set if we should verify the peer in ssl handshake, set 1 to verify. */ + ssl_verifypeer = 64, + /** The CApath or CAfile used to validate the peer certificate + this option is used only if SSL_VERIFYPEER is true */ + cainfo = 10_065, + /* 66 = OBSOLETE */ + /* 67 = OBSOLETE */ + + /** Maximum number of http redirects to follow */ + maxredirs = 68, + /** Pass a long set to 1 to get the date of the requested document (if + possible)! Pass a zero to shut it off. */ + filetime, + /** This points to a linked list of telnet options */ + telnetoptions = 10_070, + /** Max amount of cached alive connections */ + maxconnects = 71, + /** What policy to use when closing connections when the cache is filled + up */ + closepolicy, + /* 73 = OBSOLETE */ + + /** Set to explicitly use a new connection for the upcoming transfer. + Do not use this unless you're absolutely sure of this, as it makes the + operation slower and is less friendly for the network. */ + fresh_connect = 74, + /** Set to explicitly forbid the upcoming transfer's connection to be re-used + when done. Do not use this unless you're absolutely sure of this, as it + makes the operation slower and is less friendly for the network. */ + forbid_reuse, + /** Set to a file name that contains random data for libcurl to use to + seed the random engine when doing SSL connects. */ + random_file = 10_076, + /** Set to the Entropy Gathering Daemon socket pathname */ + egdsocket, + /** Time-out connect operations after this amount of seconds, if connects + are OK within this time, then fine... This only aborts the connect + phase. [Only works on unix-style/SIGALRM operating systems] */ + connecttimeout = 78, + /** Function that will be called to store headers (instead of fwrite). The + * parameters will use fwrite() syntax, make sure to follow them. */ + headerfunction = 20_079, + /** Set this to force the HTTP request to get back to GET. Only really usable + if POST, PUT or a custom request have been used first. + */ + httpget = 80, + /** Set if we should verify the Common name from the peer certificate in ssl + * handshake, set 1 to check existence, 2 to ensure that it matches the + * provided hostname. */ + ssl_verifyhost, + /** Specify which file name to write all known cookies in after completed + operation. Set file name to "-" (dash) to make it go to stdout. */ + cookiejar = 10_082, + /** Specify which SSL ciphers to use */ + ssl_cipher_list, + /** Specify which HTTP version to use! This must be set to one of the + CURL_HTTP_VERSION* enums set below. */ + http_version = 84, + /** Specifically switch on or off the FTP engine's use of the EPSV command. By + default, that one will always be attempted before the more traditional + PASV command. */ + ftp_use_epsv, + /** type of the file keeping your SSL-certificate ("DER", "PEM", "ENG") */ + sslcerttype = 10_086, + /** name of the file keeping your private SSL-key */ + sslkey, + /** type of the file keeping your private SSL-key ("DER", "PEM", "ENG") */ + sslkeytype, + /** crypto engine for the SSL-sub system */ + sslengine, + /** set the crypto engine for the SSL-sub system as default + the param has no meaning... + */ + sslengine_default = 90, + /** Non-zero value means to use the global dns cache */ + dns_use_global_cache, + /** DNS cache timeout */ + dns_cache_timeout, + /** send linked-list of pre-transfer QUOTE commands */ + prequote = 10_093, + /** set the debug function */ + debugfunction = 20_094, + /** set the data for the debug function */ + debugdata = 10_095, + /** mark this as start of a cookie session */ + cookiesession = 96, + /** The CApath directory used to validate the peer certificate + this option is used only if SSL_VERIFYPEER is true */ + capath = 10_097, + /** Instruct libcurl to use a smaller receive buffer */ + buffersize = 98, + /** Instruct libcurl to not use any signal/alarm handlers, even when using + timeouts. This option is useful for multi-threaded applications. + See libcurl-the-guide for more background information. */ + nosignal, + /** Provide a CURLShare for mutexing non-ts data */ + share = 10_100, + /** indicates type of proxy. accepted values are CURLPROXY_HTTP (default), + CURLPROXY_SOCKS4, CURLPROXY_SOCKS4A and CURLPROXY_SOCKS5. */ + proxytype = 101, + /** Set the Accept-Encoding string. Use this to tell a server you would like + the response to be compressed. */ + encoding = 10_102, + /** Set pointer to private data */ + private_opt, + /** Set aliases for HTTP 200 in the HTTP Response header */ + http200aliases, + /** Continue to send authentication (user+password) when following locations, + even when hostname changed. This can potentially send off the name + and password to whatever host the server decides. */ + unrestricted_auth = 105, + /** Specifically switch on or off the FTP engine's use of the EPRT command ( it + also disables the LPRT attempt). By default, those ones will always be + attempted before the good old traditional PORT command. */ + ftp_use_eprt, + /** Set this to a bitmask value to enable the particular authentications + methods you like. Use this in combination with CURLOPT_USERPWD. + Note that setting multiple bits may cause extra network round-trips. */ + httpauth, + /** Set the ssl context callback function, currently only for OpenSSL ssl_ctx + in second argument. The function must be matching the + curl_ssl_ctx_callback proto. */ + ssl_ctx_function = 20_108, + /** Set the userdata for the ssl context callback function's third + argument */ + ssl_ctx_data = 10_109, + /** FTP Option that causes missing dirs to be created on the remote server. + In 7.19.4 we introduced the convenience enums for this option using the + CURLFTP_CREATE_DIR prefix. + */ + ftp_create_missing_dirs = 110, + /** Set this to a bitmask value to enable the particular authentications + methods you like. Use this in combination with CURLOPT_PROXYUSERPWD. + Note that setting multiple bits may cause extra network round-trips. */ + proxyauth, + /** FTP option that changes the timeout, in seconds, associated with + getting a response. This is different from transfer timeout time and + essentially places a demand on the FTP server to acknowledge commands + in a timely manner. */ + ftp_response_timeout, + /** Set this option to one of the CURL_IPRESOLVE_* defines (see below) to + tell libcurl to resolve names to those IP versions only. This only has + affect on systems with support for more than one, i.e IPv4 _and_ IPv6. */ + ipresolve, + /** Set this option to limit the size of a file that will be downloaded from + an HTTP or FTP server. + + Note there is also _LARGE version which adds large file support for + platforms which have larger off_t sizes. See MAXFILESIZE_LARGE below. */ + maxfilesize, + /** See the comment for INFILESIZE above, but in short, specifies + * the size of the file being uploaded. -1 means unknown. + */ + infilesize_large = 30_115, + /** Sets the continuation offset. There is also a LONG version of this; + * look above for RESUME_FROM. + */ + resume_from_large, + /** Sets the maximum size of data that will be downloaded from + * an HTTP or FTP server. See MAXFILESIZE above for the LONG version. + */ + maxfilesize_large, + /** Set this option to the file name of your .netrc file you want libcurl + to parse (using the CURLOPT_NETRC option). If not set, libcurl will do + a poor attempt to find the user's home directory and check for a .netrc + file in there. */ + netrc_file = 10_118, + /** Enable SSL/TLS for FTP, pick one of: + CURLFTPSSL_TRY - try using SSL, proceed anyway otherwise + CURLFTPSSL_CONTROL - SSL for the control connection or fail + CURLFTPSSL_ALL - SSL for all communication or fail + */ + use_ssl = 119, + /** The _LARGE version of the standard POSTFIELDSIZE option */ + postfieldsize_large = 30_120, + /** Enable/disable the TCP Nagle algorithm */ + tcp_nodelay = 121, + /* 122 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ + /* 123 OBSOLETE. Gone in 7.16.0 */ + /* 124 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ + /* 125 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ + /* 126 OBSOLETE, used in 7.12.3. Gone in 7.13.0 */ + /* 127 OBSOLETE. Gone in 7.16.0 */ + /* 128 OBSOLETE. Gone in 7.16.0 */ + + /** When FTP over SSL/TLS is selected (with CURLOPT_USE_SSL), this option + can be used to change libcurl's default action which is to first try + "AUTH SSL" and then "AUTH TLS" in this order, and proceed when a OK + response has been received. + + Available parameters are: + CURLFTPAUTH_DEFAULT - let libcurl decide + CURLFTPAUTH_SSL - try "AUTH SSL" first, then TLS + CURLFTPAUTH_TLS - try "AUTH TLS" first, then SSL + */ + ftpsslauth = 129, + ioctlfunction = 20_130, /// + ioctldata = 10_131, /// + /* 132 OBSOLETE. Gone in 7.16.0 */ + /* 133 OBSOLETE. Gone in 7.16.0 */ + + /** zero terminated string for pass on to the FTP server when asked for + "account" info */ + ftp_account = 10_134, + /** feed cookies into cookie engine */ + cookielist, + /** ignore Content-Length */ + ignore_content_length = 136, + /** Set to non-zero to skip the IP address received in a 227 PASV FTP server + response. Typically used for FTP-SSL purposes but is not restricted to + that. libcurl will then instead use the same IP address it used for the + control connection. */ + ftp_skip_pasv_ip, + /** Select "file method" to use when doing FTP, see the curl_ftpmethod + above. */ + ftp_filemethod, + /** Local port number to bind the socket to */ + localport, + /** Number of ports to try, including the first one set with LOCALPORT. + Thus, setting it to 1 will make no additional attempts but the first. + */ + localportrange, + /** no transfer, set up connection and let application use the socket by + extracting it with CURLINFO_LASTSOCKET */ + connect_only, + /** Function that will be called to convert from the + network encoding (instead of using the iconv calls in libcurl) */ + conv_from_network_function = 20_142, + /** Function that will be called to convert to the + network encoding (instead of using the iconv calls in libcurl) */ + conv_to_network_function, + /** Function that will be called to convert from UTF8 + (instead of using the iconv calls in libcurl) + Note that this is used only for SSL certificate processing */ + conv_from_utf8_function, + /** If the connection proceeds too quickly then need to slow it down */ + /** */ + /** limit-rate: maximum number of bytes per second to send or receive */ + max_send_speed_large = 30_145, + max_recv_speed_large, /// ditto + /** Pointer to command string to send if USER/PASS fails. */ + ftp_alternative_to_user = 10_147, + /** callback function for setting socket options */ + sockoptfunction = 20_148, + sockoptdata = 10_149, + /** set to 0 to disable session ID re-use for this transfer, default is + enabled (== 1) */ + ssl_sessionid_cache = 150, + /** allowed SSH authentication methods */ + ssh_auth_types, + /** Used by scp/sftp to do public/private key authentication */ + ssh_public_keyfile = 10_152, + ssh_private_keyfile, + /** Send CCC (Clear Command Channel) after authentication */ + ftp_ssl_ccc = 154, + /** Same as TIMEOUT and CONNECTTIMEOUT, but with ms resolution */ + timeout_ms, + connecttimeout_ms, + /** set to zero to disable the libcurl's decoding and thus pass the raw body + data to the application even when it is encoded/compressed */ + http_transfer_decoding, + http_content_decoding, /// ditto + /** Permission used when creating new files and directories on the remote + server for protocols that support it, SFTP/SCP/FILE */ + new_file_perms, + new_directory_perms, /// ditto + /** Set the behaviour of POST when redirecting. Values must be set to one + of CURL_REDIR* defines below. This used to be called CURLOPT_POST301 */ + postredir, + /** used by scp/sftp to verify the host's public key */ + ssh_host_public_key_md5 = 10_162, + /** Callback function for opening socket (instead of socket(2)). Optionally, + callback is able change the address or refuse to connect returning + CURL_SOCKET_BAD. The callback should have type + curl_opensocket_callback */ + opensocketfunction = 20_163, + opensocketdata = 10_164, /// ditto + /** POST volatile input fields. */ + copypostfields, + /** set transfer mode (;type=$(LT)a|i$(GT)) when doing FTP via an HTTP proxy */ + proxy_transfer_mode = 166, + /** Callback function for seeking in the input stream */ + seekfunction = 20_167, + seekdata = 10_168, /// ditto + /** CRL file */ + crlfile, + /** Issuer certificate */ + issuercert, + /** (IPv6) Address scope */ + address_scope = 171, + /** Collect certificate chain info and allow it to get retrievable with + CURLINFO_CERTINFO after the transfer is complete. (Unfortunately) only + working with OpenSSL-powered builds. */ + certinfo, + /** "name" and "pwd" to use when fetching. */ + username = 10_173, + password, /// ditto + /** "name" and "pwd" to use with Proxy when fetching. */ + proxyusername, + proxypassword, /// ditto + /** Comma separated list of hostnames defining no-proxy zones. These should + match both hostnames directly, and hostnames within a domain. For + example, local.com will match local.com and www.local.com, but NOT + notlocal.com or www.notlocal.com. For compatibility with other + implementations of this, .local.com will be considered to be the same as + local.com. A single * is the only valid wildcard, and effectively + disables the use of proxy. */ + noproxy, + /** block size for TFTP transfers */ + tftp_blksize = 178, + /** Socks Service */ + socks5_gssapi_service = 10_179, + /** Socks Service */ + socks5_gssapi_nec = 180, + /** set the bitmask for the protocols that are allowed to be used for the + transfer, which thus helps the app which takes URLs from users or other + external inputs and want to restrict what protocol(s) to deal + with. Defaults to CURLPROTO_ALL. */ + protocols, + /** set the bitmask for the protocols that libcurl is allowed to follow to, + as a subset of the CURLOPT_PROTOCOLS ones. That means the protocol needs + to be set in both bitmasks to be allowed to get redirected to. Defaults + to all protocols except FILE and SCP. */ + redir_protocols, + /** set the SSH knownhost file name to use */ + ssh_knownhosts = 10_183, + /** set the SSH host key callback, must point to a curl_sshkeycallback + function */ + ssh_keyfunction = 20_184, + /** set the SSH host key callback custom pointer */ + ssh_keydata = 10_185, + /** set the SMTP mail originator */ + mail_from, + /** set the SMTP mail receiver(s) */ + mail_rcpt, + /** FTP: send PRET before PASV */ + ftp_use_pret = 188, + /** RTSP request method (OPTIONS, SETUP, PLAY, etc...) */ + rtsp_request, + /** The RTSP session identifier */ + rtsp_session_id = 10_190, + /** The RTSP stream URI */ + rtsp_stream_uri, + /** The Transport: header to use in RTSP requests */ + rtsp_transport, + /** Manually initialize the client RTSP CSeq for this handle */ + rtsp_client_cseq = 193, + /** Manually initialize the server RTSP CSeq for this handle */ + rtsp_server_cseq, + /** The stream to pass to INTERLEAVEFUNCTION. */ + interleavedata = 10_195, + /** Let the application define a custom write method for RTP data */ + interleavefunction = 20_196, + /** Turn on wildcard matching */ + wildcardmatch = 197, + /** Directory matching callback called before downloading of an + individual file (chunk) started */ + chunk_bgn_function = 20_198, + /** Directory matching callback called after the file (chunk) + was downloaded, or skipped */ + chunk_end_function, + /** Change match (fnmatch-like) callback for wildcard matching */ + fnmatch_function, + /** Let the application define custom chunk data pointer */ + chunk_data = 10_201, + /** FNMATCH_FUNCTION user pointer */ + fnmatch_data, + /** send linked-list of name:port:address sets */ + resolve, + /** Set a username for authenticated TLS */ + tlsauth_username, + /** Set a password for authenticated TLS */ + tlsauth_password, + /** Set authentication type for authenticated TLS */ + tlsauth_type, + /** the last unused */ + lastentry, + + writedata = file, /// convenient alias + readdata = infile, /// ditto + headerdata = writeheader, /// ditto + rtspheader = httpheader, /// ditto +} +/// +alias CURLoption = int; +/// +enum CURLOPT_SERVER_RESPONSE_TIMEOUT = CurlOption.ftp_response_timeout; + +/** Below here follows defines for the CURLOPT_IPRESOLVE option. If a host + name resolves addresses using more than one IP protocol version, this + option might be handy to force libcurl to use a specific IP version. */ +enum CurlIpResolve { + whatever = 0, /** default, resolves addresses to all IP versions that your system allows */ + v4 = 1, /** resolve to ipv4 addresses */ + v6 = 2 /** resolve to ipv6 addresses */ +} + +/** three convenient "aliases" that follow the name scheme better */ +enum CURLOPT_WRITEDATA = CurlOption.file; +/// ditto +enum CURLOPT_READDATA = CurlOption.infile; +/// ditto +enum CURLOPT_HEADERDATA = CurlOption.writeheader; +/// ditto +enum CURLOPT_RTSPHEADER = CurlOption.httpheader; + +/** These enums are for use with the CURLOPT_HTTP_VERSION option. */ +enum CurlHttpVersion { + none, /** setting this means we don't care, and that we'd + like the library to choose the best possible + for us! */ + v1_0, /** please use HTTP 1.0 in the request */ + v1_1, /** please use HTTP 1.1 in the request */ + last /** *ILLEGAL* http version */ +} + +/** + * Public API enums for RTSP requests + */ +enum CurlRtspReq { + none, /// + options, /// + describe, /// + announce, /// + setup, /// + play, /// + pause, /// + teardown, /// + get_parameter, /// + set_parameter, /// + record, /// + receive, /// + last /// +} + + /** These enums are for use with the CURLOPT_NETRC option. */ +enum CurlNetRcOption { + ignored, /** The .netrc will never be read. This is the default. */ + optional /** A user:password in the URL will be preferred to one in the .netrc. */, + required, /** A user:password in the URL will be ignored. + * Unless one is set programmatically, the .netrc + * will be queried. */ + last /// +} + +/// +enum CurlSslVersion { + default_version, /// + tlsv1, /// + sslv2, /// + sslv3, /// + last /** never use */ +} + +/// +enum CurlTlsAuth { + none, /// + srp, /// + last /** never use */ +} + +/** symbols to use with CURLOPT_POSTREDIR. + CURL_REDIR_POST_301 and CURL_REDIR_POST_302 can be bitwise ORed so that + CURL_REDIR_POST_301 | CURL_REDIR_POST_302 == CURL_REDIR_POST_ALL */ +enum CurlRedir { + get_all = 0, /// + post_301 = 1, /// + post_302 = 2, /// + /// + post_all = (1 | 2) // (CURL_REDIR_POST_301|CURL_REDIR_POST_302); +} +/// +enum CurlTimeCond { + none, /// + ifmodsince, /// + ifunmodsince, /// + lastmod, /// + last /// +} +/// +alias curl_TimeCond = int; + + +/** curl_strequal() and curl_strnequal() are subject for removal in a future + libcurl, see lib/README.curlx for details */ +extern (C) { +int curl_strequal(in char *s1, in char *s2); +/// ditto +int curl_strnequal(in char *s1, in char *s2, size_t n); +} +enum CurlForm { + nothing, /********** the first one is unused ************/ + copyname, + ptrname, + namelength, + copycontents, + ptrcontents, + contentslength, + filecontent, + array, + obsolete, + file, + buffer, + bufferptr, + bufferlength, + contenttype, + contentheader, + filename, + end, + obsolete2, + stream, + lastentry /** the last unused */ +} +alias CURLformoption = int; + + +/** structure to be used as parameter for CURLFORM_ARRAY */ +extern (C) struct curl_forms +{ + CURLformoption option; /// + const(char) *value; /// +} + +/** Use this for multipart formpost building + * + * Returns code for curl_formadd() + * + * Returns: + * + * $(UL + * $(LI CURL_FORMADD_OK on success ) + * $(LI CURL_FORMADD_MEMORY if the FormInfo allocation fails ) + * $(LI CURL_FORMADD_OPTION_TWICE if one option is given twice for one Form ) + * $(LI CURL_FORMADD_NULL if a null pointer was given for a char ) + * $(LI CURL_FORMADD_MEMORY if the allocation of a FormInfo struct failed ) + * $(LI CURL_FORMADD_UNKNOWN_OPTION if an unknown option was used ) + * $(LI CURL_FORMADD_INCOMPLETE if the some FormInfo is not complete (or error) ) + * $(LI CURL_FORMADD_MEMORY if a curl_httppost struct cannot be allocated ) + * $(LI CURL_FORMADD_MEMORY if some allocation for string copying failed. ) + * $(LI CURL_FORMADD_ILLEGAL_ARRAY if an illegal option is used in an array ) + * ) + * + ***************************************************************************/ +enum CurlFormAdd { + ok, /** first, no error */ + memory, /// + option_twice, /// + null_ptr, /// + unknown_option, /// + incomplete, /// + illegal_array, /// + disabled, /** libcurl was built with this disabled */ + last /// +} +/// +alias CURLFORMcode = int; + +extern (C) { + +/** + * Name: curl_formadd() + * + * Description: + * + * Pretty advanced function for building multi-part formposts. Each invoke + * adds one part that together construct a full post. Then use + * CURLOPT_HTTPPOST to send it off to libcurl. + */ +CURLFORMcode curl_formadd(curl_httppost **httppost, curl_httppost **last_post,...); + +/** + * callback function for curl_formget() + * The void *arg pointer will be the one passed as second argument to + * curl_formget(). + * The character buffer passed to it must not be freed. + * Should return the buffer length passed to it as the argument "len" on + * success. + */ +alias curl_formget_callback = size_t function(void *arg, in char *buf, size_t len); + +/** + * Name: curl_formget() + * + * Description: + * + * Serialize a curl_httppost struct built with curl_formadd(). + * Accepts a void pointer as second argument which will be passed to + * the curl_formget_callback function. + * Returns 0 on success. + */ +int curl_formget(curl_httppost *form, void *arg, curl_formget_callback append); +/** + * Name: curl_formfree() + * + * Description: + * + * Free a multipart formpost previously built with curl_formadd(). + */ +void curl_formfree(curl_httppost *form); + +/** + * Name: curl_getenv() + * + * Description: + * + * Returns a malloc()'ed string that MUST be curl_free()ed after usage is + * complete. DEPRECATED - see lib/README.curlx + */ +char * curl_getenv(in char *variable); + +/** + * Name: curl_version() + * + * Description: + * + * Returns a static ascii string of the libcurl version. + */ +char * curl_version(); + +/** + * Name: curl_easy_escape() + * + * Description: + * + * Escapes URL strings (converts all letters consider illegal in URLs to their + * %XX versions). This function returns a new allocated string or NULL if an + * error occurred. + */ +char * curl_easy_escape(CURL *handle, in char *string, int length); + +/** the previous version: */ +char * curl_escape(in char *string, int length); + + +/** + * Name: curl_easy_unescape() + * + * Description: + * + * Unescapes URL encoding in strings (converts all %XX codes to their 8bit + * versions). This function returns a new allocated string or NULL if an error + * occurred. + * Conversion Note: On non-ASCII platforms the ASCII %XX codes are + * converted into the host encoding. + */ +char * curl_easy_unescape(CURL *handle, in char *string, int length, int *outlength); + +/** the previous version */ +char * curl_unescape(in char *string, int length); + +/** + * Name: curl_free() + * + * Description: + * + * Provided for de-allocation in the same translation unit that did the + * allocation. Added in libcurl 7.10 + */ +void curl_free(void *p); + +/** + * Name: curl_global_init() + * + * Description: + * + * curl_global_init() should be invoked exactly once for each application that + * uses libcurl and before any call of other libcurl functions. + * + * This function is not thread-safe! + */ +CURLcode curl_global_init(c_long flags); + +/** + * Name: curl_global_init_mem() + * + * Description: + * + * curl_global_init() or curl_global_init_mem() should be invoked exactly once + * for each application that uses libcurl. This function can be used to + * initialize libcurl and set user defined memory management callback + * functions. Users can implement memory management routines to check for + * memory leaks, check for mis-use of the curl library etc. User registered + * callback routines with be invoked by this library instead of the system + * memory management routines like malloc, free etc. + */ +CURLcode curl_global_init_mem( + c_long flags, + curl_malloc_callback m, + curl_free_callback f, + curl_realloc_callback r, + curl_strdup_callback s, + curl_calloc_callback c +); + +/** + * Name: curl_global_cleanup() + * + * Description: + * + * curl_global_cleanup() should be invoked exactly once for each application + * that uses libcurl + */ +void curl_global_cleanup(); +} + +/** linked-list structure for the CURLOPT_QUOTE option (and other) */ +extern (C) { + +struct curl_slist +{ + char *data; + curl_slist *next; +} + +/** + * Name: curl_slist_append() + * + * Description: + * + * Appends a string to a linked list. If no list exists, it will be created + * first. Returns the new list, after appending. + */ +curl_slist * curl_slist_append(curl_slist *, in char *); + +/** + * Name: curl_slist_free_all() + * + * Description: + * + * free a previously built curl_slist. + */ +void curl_slist_free_all(curl_slist *); + +/** + * Name: curl_getdate() + * + * Description: + * + * Returns the time, in seconds since 1 Jan 1970 of the time string given in + * the first argument. The time argument in the second parameter is unused + * and should be set to NULL. + */ +time_t curl_getdate(char *p, time_t *unused); + +/** info about the certificate chain, only for OpenSSL builds. Asked + for with CURLOPT_CERTINFO / CURLINFO_CERTINFO */ +struct curl_certinfo +{ + int num_of_certs; /** number of certificates with information */ + curl_slist **certinfo; /** for each index in this array, there's a + linked list with textual information in the + format "name: value" */ +} + +} // extern (C) end + +/// +enum CURLINFO_STRING = 0x100000; +/// +enum CURLINFO_LONG = 0x200000; +/// +enum CURLINFO_DOUBLE = 0x300000; +/// +enum CURLINFO_SLIST = 0x400000; +/// +enum CURLINFO_MASK = 0x0fffff; + +/// +enum CURLINFO_TYPEMASK = 0xf00000; + +/// +enum CurlInfo { + none, /// + effective_url = 1_048_577, /// + response_code = 2_097_154, /// + total_time = 3_145_731, /// + namelookup_time, /// + connect_time, /// + pretransfer_time, /// + size_upload, /// + size_download, /// + speed_download, /// + speed_upload, /// + header_size = 2_097_163, /// + request_size, /// + ssl_verifyresult, /// + filetime, /// + content_length_download = 3_145_743, /// + content_length_upload, /// + starttransfer_time, /// + content_type = 1_048_594, /// + redirect_time = 3_145_747, /// + redirect_count = 2_097_172, /// + private_info = 1_048_597, /// + http_connectcode = 2_097_174, /// + httpauth_avail, /// + proxyauth_avail, /// + os_errno, /// + num_connects, /// + ssl_engines = 4_194_331, /// + cookielist, /// + lastsocket = 2_097_181, /// + ftp_entry_path = 1_048_606, /// + redirect_url, /// + primary_ip, /// + appconnect_time = 3_145_761, /// + certinfo = 4_194_338, /// + condition_unmet = 2_097_187, /// + rtsp_session_id = 1_048_612, /// + rtsp_client_cseq = 2_097_189, /// + rtsp_server_cseq, /// + rtsp_cseq_recv, /// + primary_port, /// + local_ip = 1_048_617, /// + local_port = 2_097_194, /// + /** Fill in new entries below here! */ + lastone = 42 +} +/// +alias CURLINFO = int; + +/** CURLINFO_RESPONSE_CODE is the new name for the option previously known as + CURLINFO_HTTP_CODE */ +enum CURLINFO_HTTP_CODE = CurlInfo.response_code; + +/// +enum CurlClosePolicy { + none, /// + oldest, /// + least_recently_used, /// + least_traffic, /// + slowest, /// + callback, /// + last /// +} +/// +alias curl_closepolicy = int; + +/// +enum CurlGlobal { + ssl = 1, /// + win32 = 2, /// + /// + all = (1 | 2), // (CURL_GLOBAL_SSL|CURL_GLOBAL_WIN32); + nothing = 0, /// + default_ = (1 | 2) /// all +} + +/****************************************************************************** + * Setup defines, protos etc for the sharing stuff. + */ + +/** Different data locks for a single share */ +enum CurlLockData { + none, /// + /** CURL_LOCK_DATA_SHARE is used internally to say that + * the locking is just made to change the internal state of the share + * itself. + */ + share, + cookie, /// + dns, /// + ssl_session, /// + connect, /// + last /// +} +/// +alias curl_lock_data = int; + +/** Different lock access types */ +enum CurlLockAccess { + none, /** unspecified action */ + shared_access, /** for read perhaps */ + single, /** for write perhaps */ + last /** never use */ +} +/// +alias curl_lock_access = int; + +/// +alias curl_lock_function = void function(CURL *handle, curl_lock_data data, curl_lock_access locktype, void *userptr); +/// +alias curl_unlock_function = void function(CURL *handle, curl_lock_data data, void *userptr); + +/// +alias CURLSH = void; + +/// +enum CurlShError { + ok, /** all is fine */ + bad_option, /** 1 */ + in_use, /** 2 */ + invalid, /** 3 */ + nomem, /** out of memory */ + last /** never use */ +} +/// +alias CURLSHcode = int; + +/** pass in a user data pointer used in the lock/unlock callback + functions */ +enum CurlShOption { + none, /** don't use */ + share, /** specify a data type to share */ + unshare, /** specify which data type to stop sharing */ + lockfunc, /** pass in a 'curl_lock_function' pointer */ + unlockfunc, /** pass in a 'curl_unlock_function' pointer */ + userdata, /** pass in a user data pointer used in the lock/unlock + callback functions */ + last /** never use */ +} +/// +alias CURLSHoption = int; + +extern (C) { +/// +CURLSH * curl_share_init(); +/// +CURLSHcode curl_share_setopt(CURLSH *, CURLSHoption option,...); +/// +CURLSHcode curl_share_cleanup(CURLSH *); +} + +/***************************************************************************** + * Structures for querying information about the curl library at runtime. + */ + +// CURLVERSION_* +enum CurlVer { + first, /// + second, /// + third, /// + fourth, /// + last /// +} +/// +alias CURLversion = int; + +/** The 'CURLVERSION_NOW' is the symbolic name meant to be used by + basically all programs ever that want to get version information. It is + meant to be a built-in version number for what kind of struct the caller + expects. If the struct ever changes, we redefine the NOW to another enum + from above. */ +enum CURLVERSION_NOW = CurlVer.fourth; + +/// +extern (C) struct _N28 +{ + CURLversion age; /** age of the returned struct */ + const(char) *version_; /** LIBCURL_VERSION */ + uint version_num; /** LIBCURL_VERSION_NUM */ + const(char) *host; /** OS/host/cpu/machine when configured */ + int features; /** bitmask, see defines below */ + const(char) *ssl_version; /** human readable string */ + c_long ssl_version_num; /** not used anymore, always 0 */ + const(char) *libz_version; /** human readable string */ + /** protocols is terminated by an entry with a NULL protoname */ + const(char) **protocols; + /** The fields below this were added in CURLVERSION_SECOND */ + const(char) *ares; + int ares_num; + /** This field was added in CURLVERSION_THIRD */ + const(char) *libidn; + /** These field were added in CURLVERSION_FOURTH. */ + /** Same as '_libiconv_version' if built with HAVE_ICONV */ + int iconv_ver_num; + const(char) *libssh_version; /** human readable string */ +} +/// +alias curl_version_info_data = _N28; + +/// +// CURL_VERSION_* +enum CurlVersion { + ipv6 = 1, /** IPv6-enabled */ + kerberos4 = 2, /** kerberos auth is supported */ + ssl = 4, /** SSL options are present */ + libz = 8, /** libz features are present */ + ntlm = 16, /** NTLM auth is supported */ + gssnegotiate = 32, /** Negotiate auth support */ + dbg = 64, /** built with debug capabilities */ + asynchdns = 128, /** asynchronous dns resolves */ + spnego = 256, /** SPNEGO auth */ + largefile = 512, /** supports files bigger than 2GB */ + idn = 1024, /** International Domain Names support */ + sspi = 2048, /** SSPI is supported */ + conv = 4096, /** character conversions supported */ + curldebug = 8192, /** debug memory tracking supported */ + tlsauth_srp = 16_384 /** TLS-SRP auth is supported */ +} + +extern (C) { +/** + * Name: curl_version_info() + * + * Description: + * + * This function returns a pointer to a static copy of the version info + * struct. See above. + */ +curl_version_info_data * curl_version_info(CURLversion ); + +/** + * Name: curl_easy_strerror() + * + * Description: + * + * The curl_easy_strerror function may be used to turn a CURLcode value + * into the equivalent human readable error string. This is useful + * for printing meaningful error messages. + */ +const(char)* curl_easy_strerror(CURLcode ); + +/** + * Name: curl_share_strerror() + * + * Description: + * + * The curl_share_strerror function may be used to turn a CURLSHcode value + * into the equivalent human readable error string. This is useful + * for printing meaningful error messages. + */ +const(char)* curl_share_strerror(CURLSHcode ); + +/** + * Name: curl_easy_pause() + * + * Description: + * + * The curl_easy_pause function pauses or unpauses transfers. Select the new + * state by setting the bitmask, use the convenience defines below. + * + */ +CURLcode curl_easy_pause(CURL *handle, int bitmask); +} + + +/// +enum CurlPause { + recv = 1, /// + recv_cont = 0, /// + send = 4, /// + send_cont = 0, /// + /// + all = (1 | 4), // CURLPAUSE_RECV | CURLPAUSE_SEND + /// + cont = (0 | 0), // CURLPAUSE_RECV_CONT | CURLPAUSE_SEND_CONT +} + +/* unfortunately, the easy.h and multi.h include files need options and info + stuff before they can be included! */ +/* *************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +extern (C) { + /// + CURL * curl_easy_init(); + /// + CURLcode curl_easy_setopt(CURL *curl, CURLoption option,...); + /// + CURLcode curl_easy_perform(CURL *curl); + /// + void curl_easy_cleanup(CURL *curl); +} + +/** + * Name: curl_easy_getinfo() + * + * Description: + * + * Request internal information from the curl session with this function. The + * third argument MUST be a pointer to a long, a pointer to a char * or a + * pointer to a double (as the documentation describes elsewhere). The data + * pointed to will be filled in accordingly and can be relied upon only if the + * function returns CURLE_OK. This function is intended to get used *AFTER* a + * performed transfer, all results from this function are undefined until the + * transfer is completed. + */ +extern (C) CURLcode curl_easy_getinfo(CURL *curl, CURLINFO info,...); + + +/** + * Name: curl_easy_duphandle() + * + * Description: + * + * Creates a new curl session handle with the same options set for the handle + * passed in. Duplicating a handle could only be a matter of cloning data and + * options, internal state info and things like persistant connections cannot + * be transfered. It is useful in multithreaded applications when you can run + * curl_easy_duphandle() for each new thread to avoid a series of identical + * curl_easy_setopt() invokes in every thread. + */ +extern (C) CURL * curl_easy_duphandle(CURL *curl); + +/** + * Name: curl_easy_reset() + * + * Description: + * + * Re-initializes a CURL handle to the default values. This puts back the + * handle to the same state as it was in when it was just created. + * + * It does keep: live connections, the Session ID cache, the DNS cache and the + * cookies. + */ +extern (C) void curl_easy_reset(CURL *curl); + +/** + * Name: curl_easy_recv() + * + * Description: + * + * Receives data from the connected socket. Use after successful + * curl_easy_perform() with CURLOPT_CONNECT_ONLY option. + */ +extern (C) CURLcode curl_easy_recv(CURL *curl, void *buffer, size_t buflen, size_t *n); + +/** + * Name: curl_easy_send() + * + * Description: + * + * Sends data over the connected socket. Use after successful + * curl_easy_perform() with CURLOPT_CONNECT_ONLY option. + */ +extern (C) CURLcode curl_easy_send(CURL *curl, void *buffer, size_t buflen, size_t *n); + + +/* + * This header file should not really need to include "curl.h" since curl.h + * itself includes this file and we expect user applications to do #include + * <curl/curl.h> without the need for especially including multi.h. + * + * For some reason we added this include here at one point, and rather than to + * break existing (wrongly written) libcurl applications, we leave it as-is + * but with this warning attached. + */ +/* *************************************************************************** + * _ _ ____ _ + * Project ___| | | | _ \| | + * / __| | | | |_) | | + * | (__| |_| | _ <| |___ + * \___|\___/|_| \_\_____| + * + * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. + * + * This software is licensed as described in the file COPYING, which + * you should have received as part of this distribution. The terms + * are also available at http://curl.haxx.se/docs/copyright.html. + * + * You may opt to use, copy, modify, merge, publish, distribute and/or sell + * copies of the Software, and permit persons to whom the Software is + * furnished to do so, under the terms of the COPYING file. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ***************************************************************************/ + +/// +alias CURLM = void; + +/// +enum CurlM { + call_multi_perform = -1, /** please call curl_multi_perform() or curl_multi_socket*() soon */ + ok, /// + bad_handle, /** the passed-in handle is not a valid CURLM handle */ + bad_easy_handle, /** an easy handle was not good/valid */ + out_of_memory, /** if you ever get this, you're in deep sh*t */ + internal_error, /** this is a libcurl bug */ + bad_socket, /** the passed in socket argument did not match */ + unknown_option, /** curl_multi_setopt() with unsupported option */ + last, /// +} +/// +alias CURLMcode = int; + +/** just to make code nicer when using curl_multi_socket() you can now check + for CURLM_CALL_MULTI_SOCKET too in the same style it works for + curl_multi_perform() and CURLM_CALL_MULTI_PERFORM */ +enum CURLM_CALL_MULTI_SOCKET = CurlM.call_multi_perform; + +/// +enum CurlMsg +{ + none, /// + done, /** This easy handle has completed. 'result' contains + the CURLcode of the transfer */ + last, /** no used */ +} +/// +alias CURLMSG = int; + +/// +extern (C) union _N31 +{ + void *whatever; /** message-specific data */ + CURLcode result; /** return code for transfer */ +} + +/// +extern (C) struct CURLMsg +{ + CURLMSG msg; /** what this message means */ + CURL *easy_handle; /** the handle it concerns */ + _N31 data; /// +} + +/** + * Name: curl_multi_init() + * + * Desc: inititalize multi-style curl usage + * + * Returns: a new CURLM handle to use in all 'curl_multi' functions. + */ +extern (C) CURLM * curl_multi_init(); + +/** + * Name: curl_multi_add_handle() + * + * Desc: add a standard curl handle to the multi stack + * + * Returns: CURLMcode type, general multi error code. + */ +extern (C) CURLMcode curl_multi_add_handle(CURLM *multi_handle, CURL *curl_handle); + + /** + * Name: curl_multi_remove_handle() + * + * Desc: removes a curl handle from the multi stack again + * + * Returns: CURLMcode type, general multi error code. + */ +extern (C) CURLMcode curl_multi_remove_handle(CURLM *multi_handle, CURL *curl_handle); + + /** + * Name: curl_multi_fdset() + * + * Desc: Ask curl for its fd_set sets. The app can use these to select() or + * poll() on. We want curl_multi_perform() called as soon as one of + * them are ready. + * + * Returns: CURLMcode type, general multi error code. + */ + +/** tmp decl */ +alias fd_set = int; +/// +extern (C) CURLMcode curl_multi_fdset( + CURLM *multi_handle, + fd_set *read_fd_set, + fd_set *write_fd_set, + fd_set *exc_fd_set, + int *max_fd +); + + /** + * Name: curl_multi_perform() + * + * Desc: When the app thinks there's data available for curl it calls this + * function to read/write whatever there is right now. This returns + * as soon as the reads and writes are done. This function does not + * require that there actually is data available for reading or that + * data can be written, it can be called just in case. It returns + * the number of handles that still transfer data in the second + * argument's integer-pointer. + * + * Returns: CURLMcode type, general multi error code. *NOTE* that this only + * returns errors etc regarding the whole multi stack. There might + * still have occurred problems on invidual transfers even when this + * returns OK. + */ +extern (C) CURLMcode curl_multi_perform(CURLM *multi_handle, int *running_handles); + + /** + * Name: curl_multi_cleanup() + * + * Desc: Cleans up and removes a whole multi stack. It does not free or + * touch any individual easy handles in any way. We need to define + * in what state those handles will be if this function is called + * in the middle of a transfer. + * + * Returns: CURLMcode type, general multi error code. + */ +extern (C) CURLMcode curl_multi_cleanup(CURLM *multi_handle); + +/** + * Name: curl_multi_info_read() + * + * Desc: Ask the multi handle if there's any messages/informationals from + * the individual transfers. Messages include informationals such as + * error code from the transfer or just the fact that a transfer is + * completed. More details on these should be written down as well. + * + * Repeated calls to this function will return a new struct each + * time, until a special "end of msgs" struct is returned as a signal + * that there is no more to get at this point. + * + * The data the returned pointer points to will not survive calling + * curl_multi_cleanup(). + * + * The 'CURLMsg' struct is meant to be very simple and only contain + * very basic informations. If more involved information is wanted, + * we will provide the particular "transfer handle" in that struct + * and that should/could/would be used in subsequent + * curl_easy_getinfo() calls (or similar). The point being that we + * must never expose complex structs to applications, as then we'll + * undoubtably get backwards compatibility problems in the future. + * + * Returns: A pointer to a filled-in struct, or NULL if it failed or ran out + * of structs. It also writes the number of messages left in the + * queue (after this read) in the integer the second argument points + * to. + */ +extern (C) CURLMsg * curl_multi_info_read(CURLM *multi_handle, int *msgs_in_queue); + +/** + * Name: curl_multi_strerror() + * + * Desc: The curl_multi_strerror function may be used to turn a CURLMcode + * value into the equivalent human readable error string. This is + * useful for printing meaningful error messages. + * + * Returns: A pointer to a zero-terminated error message. + */ +extern (C) const(char)* curl_multi_strerror(CURLMcode ); + +/** + * Name: curl_multi_socket() and + * curl_multi_socket_all() + * + * Desc: An alternative version of curl_multi_perform() that allows the + * application to pass in one of the file descriptors that have been + * detected to have "action" on them and let libcurl perform. + * See man page for details. + */ +enum CurlPoll { + none_ = 0, /** jdrewsen - underscored in order not to clash with reserved D symbols */ + in_ = 1, /// + out_ = 2, /// + inout_ = 3, /// + remove_ = 4 /// +} + +/// +alias CURL_SOCKET_TIMEOUT = CURL_SOCKET_BAD; + +/// +enum CurlCSelect { + in_ = 0x01, /** jdrewsen - underscored in order not to clash with reserved D symbols */ + out_ = 0x02, /// + err_ = 0x04 /// +} + +extern (C) { + /// + alias curl_socket_callback = + int function(CURL *easy, /** easy handle */ + curl_socket_t s, /** socket */ + int what, /** see above */ + void *userp, /** private callback pointer */ + void *socketp); /** private socket pointer */ +} + +/** + * Name: curl_multi_timer_callback + * + * Desc: Called by libcurl whenever the library detects a change in the + * maximum number of milliseconds the app is allowed to wait before + * curl_multi_socket() or curl_multi_perform() must be called + * (to allow libcurl's timed events to take place). + * + * Returns: The callback should return zero. + */ + +extern (C) { + alias curl_multi_timer_callback = + int function(CURLM *multi, /** multi handle */ + c_long timeout_ms, /** see above */ + void *userp); /** private callback pointer */ + /// ditto + CURLMcode curl_multi_socket(CURLM *multi_handle, curl_socket_t s, int *running_handles); + /// ditto + CURLMcode curl_multi_socket_action(CURLM *multi_handle, curl_socket_t s, int ev_bitmask, int *running_handles); + /// ditto + CURLMcode curl_multi_socket_all(CURLM *multi_handle, int *running_handles); +} + +/** This macro below was added in 7.16.3 to push users who recompile to use + the new curl_multi_socket_action() instead of the old curl_multi_socket() +*/ + +/** + * Name: curl_multi_timeout() + * + * Desc: Returns the maximum number of milliseconds the app is allowed to + * wait before curl_multi_socket() or curl_multi_perform() must be + * called (to allow libcurl's timed events to take place). + * + * Returns: CURLM error code. + */ +extern (C) CURLMcode curl_multi_timeout(CURLM *multi_handle, c_long *milliseconds); + +/// +enum CurlMOption { + socketfunction = 20_001, /** This is the socket callback function pointer */ + socketdata = 10_002, /** This is the argument passed to the socket callback */ + pipelining = 3, /** set to 1 to enable pipelining for this multi handle */ + timerfunction = 20_004, /** This is the timer callback function pointer */ + timerdata = 10_005, /** This is the argument passed to the timer callback */ + maxconnects = 6, /** maximum number of entries in the connection cache */ + lastentry /// +} +/// +alias CURLMoption = int; + +/** + * Name: curl_multi_setopt() + * + * Desc: Sets options for the multi handle. + * + * Returns: CURLM error code. + */ +extern (C) CURLMcode curl_multi_setopt(CURLM *multi_handle, CURLMoption option,...); + +/** + * Name: curl_multi_assign() + * + * Desc: This function sets an association in the multi handle between the + * given socket and a private pointer of the application. This is + * (only) useful for curl_multi_socket uses. + * + * Returns: CURLM error code. + */ +extern (C) CURLMcode curl_multi_assign(CURLM *multi_handle, curl_socket_t sockfd, void *sockp); diff --git a/libphobos/src/etc/c/sqlite3.d b/libphobos/src/etc/c/sqlite3.d new file mode 100644 index 0000000..43a72f5 --- /dev/null +++ b/libphobos/src/etc/c/sqlite3.d @@ -0,0 +1,2126 @@ +module etc.c.sqlite3; +/* +** 2001 September 15 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +************************************************************************* +** This header file defines the interface that the SQLite library +** presents to client programs. If a C-function, structure, datatype, +** or constant definition does not appear in this file, then it is +** not a published API of SQLite, is subject to change without +** notice, and should not be referenced by programs that use SQLite. +** +** Some of the definitions that are in this file are marked as +** "experimental". Experimental interfaces are normally new +** features recently added to SQLite. We do not anticipate changes +** to experimental interfaces but reserve the right to make minor changes +** if experience from use "in the wild" suggest such changes are prudent. +** +** The official C-language API documentation for SQLite is derived +** from comments in this file. This file is the authoritative source +** on how SQLite interfaces are suppose to operate. +** +** The name of this file under configuration management is "sqlite.h.in". +** The makefile makes some minor changes to this file (such as inserting +** the version number) and changes its name to "sqlite3.h" as +** part of the build process. +*/ + +import core.stdc.stdarg : va_list; + +extern (C) __gshared nothrow: + +/** +** CAPI3REF: Compile-Time Library Version Numbers +*/ +enum SQLITE_VERSION = "3.10.2"; +/// Ditto +enum SQLITE_VERSION_NUMBER = 3_010_002; +/// Ditto +enum SQLITE_SOURCE_ID = "2016-01-20 15:27:19 17efb4209f97fb4971656086b138599a91a75ff9"; + +/** +** CAPI3REF: Run-Time Library Version Numbers +*/ +extern immutable(char)* sqlite3_version; +/// Ditto +immutable(char)* sqlite3_libversion(); +/// Ditto +immutable(char)* sqlite3_sourceid(); +/// Ditto +int sqlite3_libversion_number(); + +/** +** CAPI3REF: Run-Time Library Compilation Options Diagnostics +*/ +int sqlite3_compileoption_used(const char *zOptName); +/// Ditto +immutable(char)* sqlite3_compileoption_get(int N); + +/** +** CAPI3REF: Test To See If The Library Is Threadsafe +*/ +int sqlite3_threadsafe(); + +/** +** CAPI3REF: Database Connection Handle +*/ +struct sqlite3; + +/// +alias sqlite3_int64 = long; +/// +alias sqlite3_uint64 = ulong; + +/** +** CAPI3REF: Closing A Database Connection +** +*/ +int sqlite3_close(sqlite3 *); +int sqlite3_close_v2(sqlite3*); + +/** +** The type for a callback function. +** This is legacy and deprecated. It is included for historical +** compatibility and is not documented. +*/ +alias sqlite3_callback = int function (void*,int,char**, char**); + +/** +** CAPI3REF: One-Step Query Execution Interface +*/ +int sqlite3_exec( + sqlite3*, /** An open database */ + const(char)*sql, /** SQL to be evaluated */ + int function (void*,int,char**,char**) callback, /** Callback function */ + void *, /** 1st argument to callback */ + char **errmsg /** Error msg written here */ +); + +/** +** CAPI3REF: Result Codes +*/ +enum +{ + SQLITE_OK = 0, /** Successful result */ +/* beginning-of-error-codes */ +/// Ditto + SQLITE_ERROR = 1, /** SQL error or missing database */ + SQLITE_INTERNAL = 2, /** Internal logic error in SQLite */ + SQLITE_PERM = 3, /** Access permission denied */ + SQLITE_ABORT = 4, /** Callback routine requested an abort */ + SQLITE_BUSY = 5, /** The database file is locked */ + SQLITE_LOCKED = 6, /** A table in the database is locked */ + SQLITE_NOMEM = 7, /** A malloc() failed */ + SQLITE_READONLY = 8, /** Attempt to write a readonly database */ + SQLITE_INTERRUPT = 9, /** Operation terminated by sqlite3_interrupt()*/ + SQLITE_IOERR = 10, /** Some kind of disk I/O error occurred */ + SQLITE_CORRUPT = 11, /** The database disk image is malformed */ + SQLITE_NOTFOUND = 12, /** Unknown opcode in sqlite3_file_control() */ + SQLITE_FULL = 13, /** Insertion failed because database is full */ + SQLITE_CANTOPEN = 14, /** Unable to open the database file */ + SQLITE_PROTOCOL = 15, /** Database lock protocol error */ + SQLITE_EMPTY = 16, /** Database is empty */ + SQLITE_SCHEMA = 17, /** The database schema changed */ + SQLITE_TOOBIG = 18, /** String or BLOB exceeds size limit */ + SQLITE_CONSTRAINT = 19, /** Abort due to constraint violation */ + SQLITE_MISMATCH = 20, /** Data type mismatch */ + SQLITE_MISUSE = 21, /** Library used incorrectly */ + SQLITE_NOLFS = 22, /** Uses OS features not supported on host */ + SQLITE_AUTH = 23, /** Authorization denied */ + SQLITE_FORMAT = 24, /** Auxiliary database format error */ + SQLITE_RANGE = 25, /** 2nd parameter to sqlite3_bind out of range */ + SQLITE_NOTADB = 26, /** File opened that is not a database file */ + SQLITE_NOTICE = 27, + SQLITE_WARNING = 28, + SQLITE_ROW = 100, /** sqlite3_step() has another row ready */ + SQLITE_DONE = 101 /** sqlite3_step() has finished executing */ +} +/* end-of-error-codes */ + +/** +** CAPI3REF: Extended Result Codes +*/ +enum +{ + SQLITE_IOERR_READ = (SQLITE_IOERR | (1 << 8)), + SQLITE_IOERR_SHORT_READ = (SQLITE_IOERR | (2 << 8)), + SQLITE_IOERR_WRITE = (SQLITE_IOERR | (3 << 8)), + SQLITE_IOERR_FSYNC = (SQLITE_IOERR | (4 << 8)), + SQLITE_IOERR_DIR_FSYNC = (SQLITE_IOERR | (5 << 8)), + SQLITE_IOERR_TRUNCATE = (SQLITE_IOERR | (6 << 8)), + SQLITE_IOERR_FSTAT = (SQLITE_IOERR | (7 << 8)), + SQLITE_IOERR_UNLOCK = (SQLITE_IOERR | (8 << 8)), + SQLITE_IOERR_RDLOCK = (SQLITE_IOERR | (9 << 8)), + SQLITE_IOERR_DELETE = (SQLITE_IOERR | (10 << 8)), + SQLITE_IOERR_BLOCKED = (SQLITE_IOERR | (11 << 8)), + SQLITE_IOERR_NOMEM = (SQLITE_IOERR | (12 << 8)), + SQLITE_IOERR_ACCESS = (SQLITE_IOERR | (13 << 8)), + SQLITE_IOERR_CHECKRESERVEDLOCK = (SQLITE_IOERR | (14 << 8)), + SQLITE_IOERR_LOCK = (SQLITE_IOERR | (15 << 8)), + SQLITE_IOERR_CLOSE = (SQLITE_IOERR | (16 << 8)), + SQLITE_IOERR_DIR_CLOSE = (SQLITE_IOERR | (17 << 8)), + SQLITE_IOERR_SHMOPEN = (SQLITE_IOERR | (18 << 8)), + SQLITE_IOERR_SHMSIZE = (SQLITE_IOERR | (19 << 8)), + SQLITE_IOERR_SHMLOCK = (SQLITE_IOERR | (20 << 8)), + SQLITE_IOERR_SHMMAP = (SQLITE_IOERR | (21 << 8)), + SQLITE_IOERR_SEEK = (SQLITE_IOERR | (22 << 8)), + SQLITE_IOERR_DELETE_NOENT = (SQLITE_IOERR | (23 << 8)), + SQLITE_IOERR_MMAP = (SQLITE_IOERR | (24 << 8)), + SQLITE_LOCKED_SHAREDCACHE = (SQLITE_LOCKED | (1 << 8)), + SQLITE_BUSY_RECOVERY = (SQLITE_BUSY | (1 << 8)), + SQLITE_CANTOPEN_NOTEMPDIR = (SQLITE_CANTOPEN | (1 << 8)), + SQLITE_IOERR_GETTEMPPATH = (SQLITE_IOERR | (25 << 8)), + SQLITE_IOERR_CONVPATH = (SQLITE_IOERR | (26 << 8)), + SQLITE_BUSY_SNAPSHOT = (SQLITE_BUSY | (2 << 8)), + SQLITE_CANTOPEN_ISDIR = (SQLITE_CANTOPEN | (2 << 8)), + SQLITE_CANTOPEN_FULLPATH = (SQLITE_CANTOPEN | (3 << 8)), + SQLITE_CANTOPEN_CONVPATH = (SQLITE_CANTOPEN | (4 << 8)), + SQLITE_CORRUPT_VTAB = (SQLITE_CORRUPT | (1 << 8)), + SQLITE_READONLY_RECOVERY = (SQLITE_READONLY | (1 << 8)), + SQLITE_READONLY_CANTLOCK = (SQLITE_READONLY | (2 << 8)), + SQLITE_READONLY_ROLLBACK = (SQLITE_READONLY | (3 << 8)), + SQLITE_READONLY_DBMOVED = (SQLITE_READONLY | (4 << 8)), + SQLITE_ABORT_ROLLBACK = (SQLITE_ABORT | (2 << 8)), + SQLITE_CONSTRAINT_CHECK = (SQLITE_CONSTRAINT | (1 << 8)), + SQLITE_CONSTRAINT_COMMITHOOK = (SQLITE_CONSTRAINT | (2 << 8)), + SQLITE_CONSTRAINT_FOREIGNKEY = (SQLITE_CONSTRAINT | (3 << 8)), + SQLITE_CONSTRAINT_FUNCTION = (SQLITE_CONSTRAINT | (4 << 8)), + SQLITE_CONSTRAINT_NOTNULL = (SQLITE_CONSTRAINT | (5 << 8)), + SQLITE_CONSTRAINT_PRIMARYKEY = (SQLITE_CONSTRAINT | (6 << 8)), + SQLITE_CONSTRAINT_TRIGGER = (SQLITE_CONSTRAINT | (7 << 8)), + SQLITE_CONSTRAINT_UNIQUE = (SQLITE_CONSTRAINT | (8 << 8)), + SQLITE_CONSTRAINT_VTAB = (SQLITE_CONSTRAINT | (9 << 8)), + SQLITE_CONSTRAINT_ROWID = (SQLITE_CONSTRAINT |(10 << 8)), + SQLITE_NOTICE_RECOVER_WAL = (SQLITE_NOTICE | (1 << 8)), + SQLITE_NOTICE_RECOVER_ROLLBACK = (SQLITE_NOTICE | (2 << 8)), + SQLITE_WARNING_AUTOINDEX = (SQLITE_WARNING | (1 << 8)), + SQLITE_AUTH_USER = (SQLITE_AUTH | (1 << 8)) +} + +/** +** CAPI3REF: Flags For File Open Operations +*/ +enum +{ + SQLITE_OPEN_READONLY = 0x00000001, /** Ok for sqlite3_open_v2() */ + SQLITE_OPEN_READWRITE = 0x00000002, /** Ok for sqlite3_open_v2() */ + SQLITE_OPEN_CREATE = 0x00000004, /** Ok for sqlite3_open_v2() */ + SQLITE_OPEN_DELETEONCLOSE = 0x00000008, /** VFS only */ + SQLITE_OPEN_EXCLUSIVE = 0x00000010, /** VFS only */ + SQLITE_OPEN_AUTOPROXY = 0x00000020, /** VFS only */ + SQLITE_OPEN_URI = 0x00000040, /** Ok for sqlite3_open_v2() */ + SQLITE_OPEN_MEMORY = 0x00000080, /** Ok for sqlite3_open_v2() */ + SQLITE_OPEN_MAIN_DB = 0x00000100, /** VFS only */ + SQLITE_OPEN_TEMP_DB = 0x00000200, /** VFS only */ + SQLITE_OPEN_TRANSIENT_DB = 0x00000400, /** VFS only */ + SQLITE_OPEN_MAIN_JOURNAL = 0x00000800, /** VFS only */ + SQLITE_OPEN_TEMP_JOURNAL = 0x00001000, /** VFS only */ + SQLITE_OPEN_SUBJOURNAL = 0x00002000, /** VFS only */ + SQLITE_OPEN_MASTER_JOURNAL = 0x00004000, /** VFS only */ + SQLITE_OPEN_NOMUTEX = 0x00008000, /** Ok for sqlite3_open_v2() */ + SQLITE_OPEN_FULLMUTEX = 0x00010000, /** Ok for sqlite3_open_v2() */ + SQLITE_OPEN_SHAREDCACHE = 0x00020000, /** Ok for sqlite3_open_v2() */ + SQLITE_OPEN_PRIVATECACHE = 0x00040000, /** Ok for sqlite3_open_v2() */ + SQLITE_OPEN_WAL = 0x00080000 /** VFS only */ +} + +/** +** CAPI3REF: Device Characteristics +*/ +enum +{ + SQLITE_IOCAP_ATOMIC = 0x00000001, + SQLITE_IOCAP_ATOMIC512 = 0x00000002, + SQLITE_IOCAP_ATOMIC1K = 0x00000004, + SQLITE_IOCAP_ATOMIC2K = 0x00000008, + SQLITE_IOCAP_ATOMIC4K = 0x00000010, + SQLITE_IOCAP_ATOMIC8K = 0x00000020, + SQLITE_IOCAP_ATOMIC16K = 0x00000040, + SQLITE_IOCAP_ATOMIC32K = 0x00000080, + SQLITE_IOCAP_ATOMIC64K = 0x00000100, + SQLITE_IOCAP_SAFE_APPEND = 0x00000200, + SQLITE_IOCAP_SEQUENTIAL = 0x00000400, + SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN = 0x00000800, + SQLITE_IOCAP_POWERSAFE_OVERWRITE = 0x00001000, + SQLITE_IOCAP_IMMUTABLE = 0x00002000 +} + +/** +** CAPI3REF: File Locking Levels +*/ +enum +{ + SQLITE_LOCK_NONE = 0, + SQLITE_LOCK_SHARED = 1, + SQLITE_LOCK_RESERVED = 2, + SQLITE_LOCK_PENDING = 3, + SQLITE_LOCK_EXCLUSIVE = 4 +} + +/** +** CAPI3REF: Synchronization Type Flags +*/ +enum +{ + SQLITE_SYNC_NORMAL = 0x00002, + SQLITE_SYNC_FULL = 0x00003, + SQLITE_SYNC_DATAONLY = 0x00010 +} + +/** +** CAPI3REF: OS Interface Open File Handle +*/ +struct sqlite3_file +{ + const(sqlite3_io_methods)*pMethods; /* Methods for an open file */ +} + +/** +** CAPI3REF: OS Interface File Virtual Methods Object +*/ + +struct sqlite3_io_methods +{ + int iVersion; + int function (sqlite3_file*) xClose; + int function (sqlite3_file*, void*, int iAmt, sqlite3_int64 iOfst) xRead; + int function (sqlite3_file*, const void*, int iAmt, sqlite3_int64 iOfst) xWrite; + int function (sqlite3_file*, sqlite3_int64 size) xTruncate; + int function (sqlite3_file*, int flags) xSync; + int function (sqlite3_file*, sqlite3_int64 *pSize) xFileSize; + int function (sqlite3_file*, int) xLock; + int function (sqlite3_file*, int) xUnlock; + int function (sqlite3_file*, int *pResOut) xCheckReservedLock; + int function (sqlite3_file*, int op, void *pArg) xFileControl; + int function (sqlite3_file*) xSectorSize; + int function (sqlite3_file*) xDeviceCharacteristics; + /* Methods above are valid for version 1 */ + int function (sqlite3_file*, int iPg, int pgsz, int, void **) xShmMap; + int function (sqlite3_file*, int offset, int n, int flags) xShmLock; + void function (sqlite3_file*) xShmBarrier; + int function (sqlite3_file*, int deleteFlag) xShmUnmap; + /* Methods above are valid for version 2 */ + /* Additional methods may be added in future releases */ + int function (sqlite3_file*, sqlite3_int64 iOfst, int iAmt, void **pp) xFetch; + int function (sqlite3_file*, sqlite3_int64 iOfst, void *p) xUnfetch; +} + +/** +** CAPI3REF: Standard File Control Opcodes +*/ +enum +{ + SQLITE_FCNTL_LOCKSTATE = 1, + SQLITE_GET_LOCKPROXYFILE = 2, + SQLITE_SET_LOCKPROXYFILE = 3, + SQLITE_LAST_ERRNO = 4, + SQLITE_FCNTL_SIZE_HINT = 5, + SQLITE_FCNTL_CHUNK_SIZE = 6, + SQLITE_FCNTL_FILE_POINTER = 7, + SQLITE_FCNTL_SYNC_OMITTED = 8, + SQLITE_FCNTL_WIN32_AV_RETRY = 9, + SQLITE_FCNTL_PERSIST_WAL = 10, + SQLITE_FCNTL_OVERWRITE = 11, + SQLITE_FCNTL_VFSNAME = 12, + SQLITE_FCNTL_POWERSAFE_OVERWRITE = 13, + SQLITE_FCNTL_PRAGMA = 14, + SQLITE_FCNTL_BUSYHANDLER = 15, + SQLITE_FCNTL_TEMPFILENAME = 16, + SQLITE_FCNTL_MMAP_SIZE = 18, + SQLITE_FCNTL_TRACE = 19, + SQLITE_FCNTL_HAS_MOVED = 20, + SQLITE_FCNTL_SYNC = 21, + SQLITE_FCNTL_COMMIT_PHASETWO = 22, + SQLITE_FCNTL_WIN32_SET_HANDLE = 23, + SQLITE_FCNTL_WAL_BLOCK = 24, + SQLITE_FCNTL_ZIPVFS = 25, + SQLITE_FCNTL_RBU = 26, + SQLITE_FCNTL_VFS_POINTER = 27, +} + +/** +** CAPI3REF: Mutex Handle +*/ +struct sqlite3_mutex; + +/** +** CAPI3REF: OS Interface Object +*/ + +alias xDlSymReturn = void * function(); +/// Ditto +alias sqlite3_syscall_ptr = void function(); + +struct sqlite3_vfs +{ + int iVersion; /** Structure version number (currently 2) */ + int szOsFile; /** Size of subclassed sqlite3_file */ + int mxPathname; /** Maximum file pathname length */ + sqlite3_vfs *pNext; /** Next registered VFS */ + const(char)*zName; /** Name of this virtual file system */ + void *pAppData; /** Pointer to application-specific data */ + int function (sqlite3_vfs*, const char *zName, sqlite3_file*, + int flags, int *pOutFlags) xOpen; + int function (sqlite3_vfs*, const char *zName, int syncDir) xDelete; + int function (sqlite3_vfs*, const char *zName, int flags, int *pResOut) xAccess; + int function (sqlite3_vfs*, const char *zName, int nOut, char *zOut) xFullPathname; + void* function (sqlite3_vfs*, const char *zFilename) xDlOpen; + void function (sqlite3_vfs*, int nByte, char *zErrMsg) xDlError; + xDlSymReturn function (sqlite3_vfs*,void*, const char *zSymbol) *xDlSym; + void function (sqlite3_vfs*, void*) xDlClose; + int function (sqlite3_vfs*, int nByte, char *zOut) xRandomness; + int function (sqlite3_vfs*, int microseconds) xSleep; + int function (sqlite3_vfs*, double*) xCurrentTime; + int function (sqlite3_vfs*, int, char *) xGetLastError; + /* + ** The methods above are in version 1 of the sqlite_vfs object + ** definition. Those that follow are added in version 2 or later + */ + int function (sqlite3_vfs*, sqlite3_int64*) xCurrentTimeInt64; + /* + ** The methods above are in versions 1 and 2 of the sqlite_vfs object. + ** Those below are for version 3 and greater. + */ + int function(sqlite3_vfs*, const char * zName, sqlite3_syscall_ptr) xSetSystemCall; + sqlite3_syscall_ptr function(sqlite3_vfs*, const char * zName) xGetSystemCall; + const(char)* function(sqlite3_vfs*, const char * zName) xNextSystemCall; + /* + ** The methods above are in versions 1 through 3 of the sqlite_vfs object. + ** New fields may be appended in figure versions. The iVersion + ** value will increment whenever this happens. + */ +} + +/** +** CAPI3REF: Flags for the xAccess VFS method +*/ +enum +{ + SQLITE_ACCESS_EXISTS = 0, + + SQLITE_ACCESS_READWRITE = 1, /** Used by PRAGMA temp_store_directory */ + SQLITE_ACCESS_READ = 2 /** Unused */ +} + +/** +** CAPI3REF: Flags for the xShmLock VFS method +*/ +enum +{ + SQLITE_SHM_UNLOCK = 1, + SQLITE_SHM_LOCK = 2, + SQLITE_SHM_SHARED = 4, + SQLITE_SHM_EXCLUSIVE = 8 +} + +/** +** CAPI3REF: Maximum xShmLock index +*/ +enum SQLITE_SHM_NLOCK = 8; + + +/** +** CAPI3REF: Initialize The SQLite Library +*/ +int sqlite3_initialize(); +/// Ditto +int sqlite3_shutdown(); +/// Ditto +int sqlite3_os_init(); +/// Ditto +int sqlite3_os_end(); + +/** +** CAPI3REF: Configuring The SQLite Library +*/ +int sqlite3_config(int, ...); + +/** +** CAPI3REF: Configure database connections +*/ +int sqlite3_db_config(sqlite3*, int op, ...); + +/** +** CAPI3REF: Memory Allocation Routines +*/ +struct sqlite3_mem_methods +{ + void* function (int) xMalloc; /** Memory allocation function */ + void function (void*) xFree; /** Free a prior allocation */ + void* function (void*,int) xRealloc; /** Resize an allocation */ + int function (void*) xSize; /** Return the size of an allocation */ + int function (int) xRoundup; /** Round up request size to allocation size */ + int function (void*) xInit; /** Initialize the memory allocator */ + void function (void*) xShutdown; /** Deinitialize the memory allocator */ + void *pAppData; /** Argument to xInit() and xShutdown() */ +} + +/** +** CAPI3REF: Configuration Options +*/ +enum +{ + SQLITE_CONFIG_SINGLETHREAD = 1, /** nil */ + SQLITE_CONFIG_MULTITHREAD = 2, /** nil */ + SQLITE_CONFIG_SERIALIZED = 3, /** nil */ + SQLITE_CONFIG_MALLOC = 4, /** sqlite3_mem_methods* */ + SQLITE_CONFIG_GETMALLOC = 5, /** sqlite3_mem_methods* */ + SQLITE_CONFIG_SCRATCH = 6, /** void*, int sz, int N */ + SQLITE_CONFIG_PAGECACHE = 7, /** void*, int sz, int N */ + SQLITE_CONFIG_HEAP = 8, /** void*, int nByte, int min */ + SQLITE_CONFIG_MEMSTATUS = 9, /** boolean */ + SQLITE_CONFIG_MUTEX = 10, /** sqlite3_mutex_methods* */ + SQLITE_CONFIG_GETMUTEX = 11, /** sqlite3_mutex_methods* */ +/* previously SQLITE_CONFIG_CHUNKALLOC 12 which is now unused. */ + SQLITE_CONFIG_LOOKASIDE = 13, /** int int */ + SQLITE_CONFIG_PCACHE = 14, /** sqlite3_pcache_methods* */ + SQLITE_CONFIG_GETPCACHE = 15, /** sqlite3_pcache_methods* */ + SQLITE_CONFIG_LOG = 16, /** xFunc, void* */ + SQLITE_CONFIG_URI = 17, + SQLITE_CONFIG_PCACHE2 = 18, + SQLITE_CONFIG_GETPCACHE2 = 19, + SQLITE_CONFIG_COVERING_INDEX_SCAN = 20, + SQLITE_CONFIG_SQLLOG = 21, + SQLITE_CONFIG_MMAP_SIZE = 22, + SQLITE_CONFIG_WIN32_HEAPSIZE = 23, + SQLITE_CONFIG_PCACHE_HDRSZ = 24, + SQLITE_CONFIG_PMASZ = 25, +} + +/** +** CAPI3REF: Database Connection Configuration Options +*/ +enum +{ + SQLITE_DBCONFIG_LOOKASIDE = 1001, /** void* int int */ + SQLITE_DBCONFIG_ENABLE_FKEY = 1002, /** int int* */ + SQLITE_DBCONFIG_ENABLE_TRIGGER = 1003 /** int int* */ +} + + +/** +** CAPI3REF: Enable Or Disable Extended Result Codes +*/ +int sqlite3_extended_result_codes(sqlite3*, int onoff); + +/** +** CAPI3REF: Last Insert Rowid +*/ +sqlite3_int64 sqlite3_last_insert_rowid(sqlite3*); + +/** +** CAPI3REF: Count The Number Of Rows Modified +*/ +int sqlite3_changes(sqlite3*); + +/** +** CAPI3REF: Total Number Of Rows Modified +*/ +int sqlite3_total_changes(sqlite3*); + +/** +** CAPI3REF: Interrupt A Long-Running Query +*/ +void sqlite3_interrupt(sqlite3*); + +/** +** CAPI3REF: Determine If An SQL Statement Is Complete +*/ +int sqlite3_complete(const char *sql); +/// Ditto +int sqlite3_complete16(const void *sql); + +/** +** CAPI3REF: Register A Callback To Handle SQLITE_BUSY Errors +*/ +int sqlite3_busy_handler(sqlite3*, int function (void*,int), void*); + +/** +** CAPI3REF: Set A Busy Timeout +*/ +int sqlite3_busy_timeout(sqlite3*, int ms); + +/** +** CAPI3REF: Convenience Routines For Running Queries +*/ +int sqlite3_get_table( + sqlite3 *db, /** An open database */ + const(char)*zSql, /** SQL to be evaluated */ + char ***pazResult, /** Results of the query */ + int *pnRow, /** Number of result rows written here */ + int *pnColumn, /** Number of result columns written here */ + char **pzErrmsg /** Error msg written here */ +); +/// +void sqlite3_free_table(char **result); + +/** +** CAPI3REF: Formatted String Printing Functions +*/ +char *sqlite3_mprintf(const char*,...); +char *sqlite3_vmprintf(const char*, va_list); +char *sqlite3_snprintf(int,char*,const char*, ...); +char *sqlite3_vsnprintf(int,char*,const char*, va_list); + +/** +** CAPI3REF: Memory Allocation Subsystem +*/ +void *sqlite3_malloc(int); +/// Ditto +void *sqlite3_malloc64(sqlite3_uint64); +/// Ditto +void *sqlite3_realloc(void*, int); +/// Ditto +void *sqlite3_realloc64(void*, sqlite3_uint64); +/// Ditto +void sqlite3_free(void*); +/// Ditto +sqlite3_uint64 sqlite3_msize(void*); + +/** +** CAPI3REF: Memory Allocator Statistics +*/ +sqlite3_int64 sqlite3_memory_used(); +sqlite3_int64 sqlite3_memory_highwater(int resetFlag); + +/** +** CAPI3REF: Pseudo-Random Number Generator +*/ +void sqlite3_randomness(int N, void *P); + +/** +** CAPI3REF: Compile-Time Authorization Callbacks +*/ +int sqlite3_set_authorizer( + sqlite3*, + int function (void*,int,const char*,const char*,const char*,const char*) xAuth, + void *pUserData +); + +/** +** CAPI3REF: Authorizer Return Codes +*/ +enum +{ + SQLITE_DENY = 1, /** Abort the SQL statement with an error */ + SQLITE_IGNORE = 2 /** Don't allow access, but don't generate an error */ +} + +/** +** CAPI3REF: Authorizer Action Codes +*/ +/******************************************* 3rd ************ 4th ***********/ +enum +{ + SQLITE_CREATE_INDEX = 1, /** Index Name Table Name */ + SQLITE_CREATE_TABLE = 2, /** Table Name NULL */ + SQLITE_CREATE_TEMP_INDEX = 3, /** Index Name Table Name */ + SQLITE_CREATE_TEMP_TABLE = 4, /** Table Name NULL */ + SQLITE_CREATE_TEMP_TRIGGER = 5, /** Trigger Name Table Name */ + SQLITE_CREATE_TEMP_VIEW = 6, /** View Name NULL */ + SQLITE_CREATE_TRIGGER = 7, /** Trigger Name Table Name */ + SQLITE_CREATE_VIEW = 8, /** View Name NULL */ + SQLITE_DELETE = 9, /** Table Name NULL */ + SQLITE_DROP_INDEX = 10, /** Index Name Table Name */ + SQLITE_DROP_TABLE = 11, /** Table Name NULL */ + SQLITE_DROP_TEMP_INDEX = 12, /** Index Name Table Name */ + SQLITE_DROP_TEMP_TABLE = 13, /** Table Name NULL */ + SQLITE_DROP_TEMP_TRIGGER = 14, /** Trigger Name Table Name */ + SQLITE_DROP_TEMP_VIEW = 15, /** View Name NULL */ + SQLITE_DROP_TRIGGER = 16, /** Trigger Name Table Name */ + SQLITE_DROP_VIEW = 17, /** View Name NULL */ + SQLITE_INSERT = 18, /** Table Name NULL */ + SQLITE_PRAGMA = 19, /** Pragma Name 1st arg or NULL */ + SQLITE_READ = 20, /** Table Name Column Name */ + SQLITE_SELECT = 21, /** NULL NULL */ + SQLITE_TRANSACTION = 22, /** Operation NULL */ + SQLITE_UPDATE = 23, /** Table Name Column Name */ + SQLITE_ATTACH = 24, /** Filename NULL */ + SQLITE_DETACH = 25, /** Database Name NULL */ + SQLITE_ALTER_TABLE = 26, /** Database Name Table Name */ + SQLITE_REINDEX = 27, /** Index Name NULL */ + SQLITE_ANALYZE = 28, /** Table Name NULL */ + SQLITE_CREATE_VTABLE = 29, /** Table Name Module Name */ + SQLITE_DROP_VTABLE = 30, /** Table Name Module Name */ + SQLITE_FUNCTION = 31, /** NULL Function Name */ + SQLITE_SAVEPOINT = 32, /** Operation Savepoint Name */ + SQLITE_COPY = 0, /** No longer used */ + SQLITE_RECURSIVE = 33 +} + +/** +** CAPI3REF: Tracing And Profiling Functions +*/ +void *sqlite3_trace(sqlite3*, void function (void*,const char*) xTrace, void*); +/// Ditto +void *sqlite3_profile(sqlite3*, void function (void*,const char*,sqlite3_uint64) xProfile, void*); + +/** +** CAPI3REF: Query Progress Callbacks +*/ +void sqlite3_progress_handler(sqlite3*, int, int function (void*), void*); + +/** +** CAPI3REF: Opening A New Database Connection +*/ +int sqlite3_open( + const(char)*filename, /** Database filename (UTF-8) */ + sqlite3 **ppDb /** OUT: SQLite db handle */ +); +/// Ditto +int sqlite3_open16( + const(void)*filename, /** Database filename (UTF-16) */ + sqlite3 **ppDb /** OUT: SQLite db handle */ +); +/// Ditto +int sqlite3_open_v2( + const(char)*filename, /** Database filename (UTF-8) */ + sqlite3 **ppDb, /** OUT: SQLite db handle */ + int flags, /** Flags */ + const(char)*zVfs /** Name of VFS module to use */ +); + +/* +** CAPI3REF: Obtain Values For URI Parameters +*/ +const(char)* sqlite3_uri_parameter(const(char)* zFilename, const(char)* zParam); +/// Ditto +int sqlite3_uri_boolean(const(char)* zFile, const(char)* zParam, int bDefault); +/// Ditto +sqlite3_int64 sqlite3_uri_int64(const char*, const char*, sqlite3_int64); + +/** +** CAPI3REF: Error Codes And Messages +*/ +int sqlite3_errcode(sqlite3 *db); +/// Ditto +int sqlite3_extended_errcode(sqlite3 *db); +/// Ditto +const(char)* sqlite3_errmsg(sqlite3*); +/// Ditto +const(void)* sqlite3_errmsg16(sqlite3*); +/// Ditto +const(char)* sqlite3_errstr(int); + +/** +** CAPI3REF: SQL Statement Object +*/ +struct sqlite3_stmt; + +/** +** CAPI3REF: Run-time Limits +*/ +int sqlite3_limit(sqlite3*, int id, int newVal); + +/** +** CAPI3REF: Run-Time Limit Categories +*/ +enum +{ + SQLITE_LIMIT_LENGTH = 0, + SQLITE_LIMIT_SQL_LENGTH = 1, + SQLITE_LIMIT_COLUMN = 2, + SQLITE_LIMIT_EXPR_DEPTH = 3, + SQLITE_LIMIT_COMPOUND_SELECT = 4, + SQLITE_LIMIT_VDBE_OP = 5, + SQLITE_LIMIT_FUNCTION_ARG = 6, + SQLITE_LIMIT_ATTACHED = 7, + SQLITE_LIMIT_LIKE_PATTERN_LENGTH = 8, + SQLITE_LIMIT_VARIABLE_NUMBER = 9, + SQLITE_LIMIT_TRIGGER_DEPTH = 10, + SQLITE_LIMIT_WORKER_THREADS = 11, +} + +/** +** CAPI3REF: Compiling An SQL Statement +*/ +int sqlite3_prepare( + sqlite3 *db, /** Database handle */ + const(char)*zSql, /** SQL statement, UTF-8 encoded */ + int nByte, /** Maximum length of zSql in bytes. */ + sqlite3_stmt **ppStmt, /** OUT: Statement handle */ + const(char*)*pzTail /** OUT: Pointer to unused portion of zSql */ +); +/// Ditto +int sqlite3_prepare_v2( + sqlite3 *db, /** Database handle */ + const(char)*zSql, /** SQL statement, UTF-8 encoded */ + int nByte, /** Maximum length of zSql in bytes. */ + sqlite3_stmt **ppStmt, /** OUT: Statement handle */ + const(char*)*pzTail /** OUT: Pointer to unused portion of zSql */ +); +/// Ditto +int sqlite3_prepare16( + sqlite3 *db, /** Database handle */ + const(void)*zSql, /** SQL statement, UTF-16 encoded */ + int nByte, /** Maximum length of zSql in bytes. */ + sqlite3_stmt **ppStmt, /** OUT: Statement handle */ + const(void*)*pzTail /** OUT: Pointer to unused portion of zSql */ +); +/// Ditto +int sqlite3_prepare16_v2( + sqlite3 *db, /** Database handle */ + const(void)*zSql, /** SQL statement, UTF-16 encoded */ + int nByte, /** Maximum length of zSql in bytes. */ + sqlite3_stmt **ppStmt, /** OUT: Statement handle */ + const(void*)*pzTail /** OUT: Pointer to unused portion of zSql */ +); + +/** +** CAPI3REF: Retrieving Statement SQL +*/ +const(char)* sqlite3_sql(sqlite3_stmt *pStmt); + +/* +** CAPI3REF: Determine If An SQL Statement Writes The Database +*/ +int sqlite3_stmt_readonly(sqlite3_stmt *pStmt); + +/** +** CAPI3REF: Determine If A Prepared Statement Has Been Reset +*/ +int sqlite3_stmt_busy(sqlite3_stmt*); + + +/** +** CAPI3REF: Dynamically Typed Value Object +*/ +struct sqlite3_value; + +/** +** CAPI3REF: SQL Function Context Object +*/ +struct sqlite3_context; + +/** +** CAPI3REF: Binding Values To Prepared Statements +*/ +int sqlite3_bind_blob(sqlite3_stmt*, int, const void*, int n, void function (void*)); +/// Ditto +int sqlite3_bind_blob64(sqlite3_stmt*, int, const void*, sqlite3_uint64,void function (void*)); +/// Ditto +int sqlite3_bind_double(sqlite3_stmt*, int, double); +/// Ditto +int sqlite3_bind_int(sqlite3_stmt*, int, int); +/// Ditto +int sqlite3_bind_int64(sqlite3_stmt*, int, sqlite3_int64); +/// Ditto +int sqlite3_bind_null(sqlite3_stmt*, int); +/// Ditto +int sqlite3_bind_text(sqlite3_stmt*, int, const char*, int n, void function (void*)); +/// Ditto +int sqlite3_bind_text16(sqlite3_stmt*, int, const void*, int, void function (void*)); +/// Ditto +int sqlite3_bind_text64(sqlite3_stmt*, int, const char*, sqlite3_uint64,void function (void*), ubyte encoding); +/// Ditto +int sqlite3_bind_value(sqlite3_stmt*, int, const sqlite3_value*); +/// Ditto +int sqlite3_bind_zeroblob(sqlite3_stmt*, int, int n); +/// Ditto +int sqlite3_bind_zeroblob64(sqlite3_stmt*, int, sqlite3_uint64 n); + +/** +** CAPI3REF: Number Of SQL Parameters +*/ +int sqlite3_bind_parameter_count(sqlite3_stmt*); + +/** +** CAPI3REF: Name Of A Host Parameter +*/ +const(char)* sqlite3_bind_parameter_name(sqlite3_stmt*, int); + +/** +** CAPI3REF: Index Of A Parameter With A Given Name +*/ +int sqlite3_bind_parameter_index(sqlite3_stmt*, const char *zName); + +/** +** CAPI3REF: Reset All Bindings On A Prepared Statement +*/ +int sqlite3_clear_bindings(sqlite3_stmt*); + +/** +** CAPI3REF: Number Of Columns In A Result Set +*/ +int sqlite3_column_count(sqlite3_stmt *pStmt); + +/** +** CAPI3REF: Column Names In A Result Set +*/ +const(char)* sqlite3_column_name(sqlite3_stmt*, int N); +/// Ditto +const(void)* sqlite3_column_name16(sqlite3_stmt*, int N); + +/** +** CAPI3REF: Source Of Data In A Query Result +*/ +const(char)* sqlite3_column_database_name(sqlite3_stmt*,int); +/// Ditto +const(void)* sqlite3_column_database_name16(sqlite3_stmt*,int); +/// Ditto +const(char)* sqlite3_column_table_name(sqlite3_stmt*,int); +/// Ditto +const (void)* sqlite3_column_table_name16(sqlite3_stmt*,int); +/// Ditto +const (char)* sqlite3_column_origin_name(sqlite3_stmt*,int); +/// Ditto +const (void)* sqlite3_column_origin_name16(sqlite3_stmt*,int); + +/** +** CAPI3REF: Declared Datatype Of A Query Result +*/ +const (char)* sqlite3_column_decltype(sqlite3_stmt*,int); +/// Ditto +const (void)* sqlite3_column_decltype16(sqlite3_stmt*,int); + +/** +** CAPI3REF: Evaluate An SQL Statement +*/ +int sqlite3_step(sqlite3_stmt*); + +/** +** CAPI3REF: Number of columns in a result set +*/ +int sqlite3_data_count(sqlite3_stmt *pStmt); + +/** +** CAPI3REF: Fundamental Datatypes +*/ +enum +{ + SQLITE_INTEGER = 1, + SQLITE_FLOAT = 2, + SQLITE_BLOB = 4, + SQLITE_NULL = 5, + SQLITE3_TEXT = 3 +} + +/** +** CAPI3REF: Result Values From A Query +*/ +const (void)* sqlite3_column_blob(sqlite3_stmt*, int iCol); +/// Ditto +int sqlite3_column_bytes(sqlite3_stmt*, int iCol); +/// Ditto +int sqlite3_column_bytes16(sqlite3_stmt*, int iCol); +/// Ditto +double sqlite3_column_double(sqlite3_stmt*, int iCol); +/// Ditto +int sqlite3_column_int(sqlite3_stmt*, int iCol); +/// Ditto +sqlite3_int64 sqlite3_column_int64(sqlite3_stmt*, int iCol); +/// Ditto +const (char)* sqlite3_column_text(sqlite3_stmt*, int iCol); +/// Ditto +const (void)* sqlite3_column_text16(sqlite3_stmt*, int iCol); +/// Ditto +int sqlite3_column_type(sqlite3_stmt*, int iCol); +/// Ditto +sqlite3_value *sqlite3_column_value(sqlite3_stmt*, int iCol); + +/** +** CAPI3REF: Destroy A Prepared Statement Object +*/ +int sqlite3_finalize(sqlite3_stmt *pStmt); + +/** +** CAPI3REF: Reset A Prepared Statement Object +*/ +int sqlite3_reset(sqlite3_stmt *pStmt); + +/** +** CAPI3REF: Create Or Redefine SQL Functions +*/ +int sqlite3_create_function( + sqlite3 *db, + const(char)*zFunctionName, + int nArg, + int eTextRep, + void *pApp, + void function (sqlite3_context*,int,sqlite3_value**) xFunc, + void function (sqlite3_context*,int,sqlite3_value**) xStep, + void function (sqlite3_context*) xFinal +); +/// Ditto +int sqlite3_create_function16( + sqlite3 *db, + const(void)*zFunctionName, + int nArg, + int eTextRep, + void *pApp, + void function (sqlite3_context*,int,sqlite3_value**) xFunc, + void function (sqlite3_context*,int,sqlite3_value**) xStep, + void function (sqlite3_context*) xFinal +); +/// Ditto +int sqlite3_create_function_v2( + sqlite3 *db, + const(char)*zFunctionName, + int nArg, + int eTextRep, + void *pApp, + void function (sqlite3_context*,int,sqlite3_value**) xFunc, + void function (sqlite3_context*,int,sqlite3_value**) xStep, + void function (sqlite3_context*) xFinal, + void function (void*) xDestroy +); + +/** +** CAPI3REF: Text Encodings +** +** These constant define integer codes that represent the various +** text encodings supported by SQLite. +*/ +enum +{ + SQLITE_UTF8 = 1, + SQLITE_UTF16LE = 2, + SQLITE_UTF16BE = 3 +} +/// Ditto +enum +{ + SQLITE_UTF16 = 4, /** Use native byte order */ + SQLITE_ANY = 5, /** sqlite3_create_function only */ + SQLITE_UTF16_ALIGNED = 8 /** sqlite3_create_collation only */ +} + +/** +** CAPI3REF: Function Flags +*/ +enum SQLITE_DETERMINISTIC = 0x800; + +/** +** CAPI3REF: Deprecated Functions +*/ +deprecated int sqlite3_aggregate_count(sqlite3_context*); +deprecated int sqlite3_expired(sqlite3_stmt*); +deprecated int sqlite3_transfer_bindings(sqlite3_stmt*, sqlite3_stmt*); +deprecated int sqlite3_global_recover(); +deprecated void sqlite3_thread_cleanup(); +deprecated int sqlite3_memory_alarm(void function(void*,sqlite3_int64,int),void*,sqlite3_int64); + +/** +** CAPI3REF: Obtaining SQL Function Parameter Values +*/ +const (void)* sqlite3_value_blob(sqlite3_value*); +/// Ditto +int sqlite3_value_bytes(sqlite3_value*); +/// Ditto +int sqlite3_value_bytes16(sqlite3_value*); +/// Ditto +double sqlite3_value_double(sqlite3_value*); +/// Ditto +int sqlite3_value_int(sqlite3_value*); +/// Ditto +sqlite3_int64 sqlite3_value_int64(sqlite3_value*); +/// Ditto +const (char)* sqlite3_value_text(sqlite3_value*); +/// Ditto +const (void)* sqlite3_value_text16(sqlite3_value*); +/// Ditto +const (void)* sqlite3_value_text16le(sqlite3_value*); +/// Ditto +const (void)* sqlite3_value_text16be(sqlite3_value*); +/// Ditto +int sqlite3_value_type(sqlite3_value*); +/// Ditto +int sqlite3_value_numeric_type(sqlite3_value*); + +/* +** CAPI3REF: Finding The Subtype Of SQL Values +*/ +uint sqlite3_value_subtype(sqlite3_value*); + +/* +** CAPI3REF: Copy And Free SQL Values +*/ +sqlite3_value* sqlite3_value_dup(const sqlite3_value*); +void sqlite3_value_free(sqlite3_value*); + +/** +** CAPI3REF: Obtain Aggregate Function Context +*/ +void *sqlite3_aggregate_context(sqlite3_context*, int nBytes); + +/** +** CAPI3REF: User Data For Functions +*/ +void *sqlite3_user_data(sqlite3_context*); + +/** +** CAPI3REF: Database Connection For Functions +*/ +sqlite3 *sqlite3_context_db_handle(sqlite3_context*); + +/** +** CAPI3REF: Function Auxiliary Data +*/ +void *sqlite3_get_auxdata(sqlite3_context*, int N); +/// Ditto +void sqlite3_set_auxdata(sqlite3_context*, int N, void*, void function (void*)); + + +/** +** CAPI3REF: Constants Defining Special Destructor Behavior +*/ +alias sqlite3_destructor_type = void function (void*); +/// Ditto +enum +{ + SQLITE_STATIC = (cast(sqlite3_destructor_type) 0), + SQLITE_TRANSIENT = (cast (sqlite3_destructor_type) -1) +} + +/** +** CAPI3REF: Setting The Result Of An SQL Function +*/ +void sqlite3_result_blob(sqlite3_context*, const void*, int, void function(void*)); +/// Ditto +void sqlite3_result_blob64(sqlite3_context*,const void*,sqlite3_uint64,void function(void*)); +/// Ditto +void sqlite3_result_double(sqlite3_context*, double); +/// Ditto +void sqlite3_result_error(sqlite3_context*, const char*, int); +/// Ditto +void sqlite3_result_error16(sqlite3_context*, const void*, int); +/// Ditto +void sqlite3_result_error_toobig(sqlite3_context*); +/// Ditto +void sqlite3_result_error_nomem(sqlite3_context*); +/// Ditto +void sqlite3_result_error_code(sqlite3_context*, int); +/// Ditto +void sqlite3_result_int(sqlite3_context*, int); +/// Ditto +void sqlite3_result_int64(sqlite3_context*, sqlite3_int64); +/// Ditto +void sqlite3_result_null(sqlite3_context*); +/// Ditto +void sqlite3_result_text(sqlite3_context*, const char*, int, void function(void*)); +/// Ditto +void sqlite3_result_text64(sqlite3_context*, const char*,sqlite3_uint64,void function(void*), ubyte encoding); +/// Ditto +void sqlite3_result_text16(sqlite3_context*, const void*, int, void function(void*)); +/// Ditto +void sqlite3_result_text16le(sqlite3_context*, const void*, int, void function(void*)); +/// Ditto +void sqlite3_result_text16be(sqlite3_context*, const void*, int, void function(void*)); +/// Ditto +void sqlite3_result_value(sqlite3_context*, sqlite3_value*); +/// Ditto +void sqlite3_result_zeroblob(sqlite3_context*, int n); +/// Ditto +int sqlite3_result_zeroblob64(sqlite3_context*, sqlite3_uint64 n); + +/* +** CAPI3REF: Setting The Subtype Of An SQL Function +*/ +void sqlite3_result_subtype(sqlite3_context*,uint); + +/** +** CAPI3REF: Define New Collating Sequences +*/ +int sqlite3_create_collation( + sqlite3*, + const(char)*zName, + int eTextRep, + void *pArg, + int function (void*,int,const void*,int,const void*) xCompare +); +/// Ditto +int sqlite3_create_collation_v2( + sqlite3*, + const(char)*zName, + int eTextRep, + void *pArg, + int function (void*,int,const void*,int,const void*) xCompare, + void function (void*) xDestroy +); +/// Ditto +int sqlite3_create_collation16( + sqlite3*, + const(void)*zName, + int eTextRep, + void *pArg, + int function (void*,int,const void*,int,const void*) xCompare +); + +/** +** CAPI3REF: Collation Needed Callbacks +*/ +int sqlite3_collation_needed( + sqlite3*, + void*, + void function (void*,sqlite3*,int eTextRep,const char*) +); +/// Ditto +int sqlite3_collation_needed16( + sqlite3*, + void*, + void function (void*,sqlite3*,int eTextRep,const void*) +); + +/// +int sqlite3_key( + sqlite3 *db, /** Database to be rekeyed */ + const(void)*pKey, int nKey /** The key */ +); +/// Ditto +int sqlite3_key_v2( + sqlite3 *db, /* Database to be rekeyed */ + const(char)* zDbName, /* Name of the database */ + const(void)* pKey, int nKey /* The key */ +); + +/** +** Change the key on an open database. If the current database is not +** encrypted, this routine will encrypt it. If pNew == 0 or nNew == 0, the +** database is decrypted. +** +** The code to implement this API is not available in the public release +** of SQLite. +*/ +int sqlite3_rekey( + sqlite3 *db, /** Database to be rekeyed */ + const(void)*pKey, int nKey /** The new key */ +); +int sqlite3_rekey_v2( + sqlite3 *db, /* Database to be rekeyed */ + const(char)* zDbName, /* Name of the database */ + const(void)* pKey, int nKey /* The new key */ +); + +/** +** Specify the activation key for a SEE database. Unless +** activated, none of the SEE routines will work. +*/ +void sqlite3_activate_see( + const(char)*zPassPhrase /** Activation phrase */ +); + +/** +** Specify the activation key for a CEROD database. Unless +** activated, none of the CEROD routines will work. +*/ +void sqlite3_activate_cerod( + const(char)*zPassPhrase /** Activation phrase */ +); + +/** +** CAPI3REF: Suspend Execution For A Short Time +*/ +int sqlite3_sleep(int); + +/** +** CAPI3REF: Name Of The Folder Holding Temporary Files +*/ +extern char *sqlite3_temp_directory; + +/** +** CAPI3REF: Name Of The Folder Holding Database Files +*/ +extern char *sqlite3_data_directory; + +/** +** CAPI3REF: Test For Auto-Commit Mode +*/ +int sqlite3_get_autocommit(sqlite3*); + +/** +** CAPI3REF: Find The Database Handle Of A Prepared Statement +*/ +sqlite3 *sqlite3_db_handle(sqlite3_stmt*); + +/** +** CAPI3REF: Return The Filename For A Database Connection +*/ +const(char)* sqlite3_db_filename(sqlite3 *db, const char* zDbName); + +/** +** CAPI3REF: Determine if a database is read-only +*/ +int sqlite3_db_readonly(sqlite3 *db, const char * zDbName); + +/* +** CAPI3REF: Find the next prepared statement +*/ +sqlite3_stmt *sqlite3_next_stmt(sqlite3 *pDb, sqlite3_stmt *pStmt); + +/** +** CAPI3REF: Commit And Rollback Notification Callbacks +*/ +void *sqlite3_commit_hook(sqlite3*, int function (void*), void*); +/// Ditto +void *sqlite3_rollback_hook(sqlite3*, void function (void *), void*); + +/** +** CAPI3REF: Data Change Notification Callbacks +*/ +void *sqlite3_update_hook( + sqlite3*, + void function (void *,int ,char *, char *, sqlite3_int64), + void* +); + +/** +** CAPI3REF: Enable Or Disable Shared Pager Cache +*/ +int sqlite3_enable_shared_cache(int); + +/** +** CAPI3REF: Attempt To Free Heap Memory +*/ +int sqlite3_release_memory(int); + +/** +** CAPI3REF: Free Memory Used By A Database Connection +*/ +int sqlite3_db_release_memory(sqlite3*); + +/* +** CAPI3REF: Impose A Limit On Heap Size +*/ +sqlite3_int64 sqlite3_soft_heap_limit64(sqlite3_int64 N); + +/** +** CAPI3REF: Deprecated Soft Heap Limit Interface +*/ +deprecated void sqlite3_soft_heap_limit(int N); + +/** +** CAPI3REF: Extract Metadata About A Column Of A Table +*/ +int sqlite3_table_column_metadata( + sqlite3 *db, /** Connection handle */ + const(char)*zDbName, /** Database name or NULL */ + const(char)*zTableName, /** Table name */ + const(char)*zColumnName, /** Column name */ + char **pzDataType, /** OUTPUT: Declared data type */ + char **pzCollSeq, /** OUTPUT: Collation sequence name */ + int *pNotNull, /** OUTPUT: True if NOT NULL constraint exists */ + int *pPrimaryKey, /** OUTPUT: True if column part of PK */ + int *pAutoinc /** OUTPUT: True if column is auto-increment */ +); + +/** +** CAPI3REF: Load An Extension +*/ +int sqlite3_load_extension( + sqlite3 *db, /** Load the extension into this database connection */ + const(char)*zFile, /** Name of the shared library containing extension */ + const(char)*zProc, /** Entry point. Derived from zFile if 0 */ + char **pzErrMsg /** Put error message here if not 0 */ +); + +/** +** CAPI3REF: Enable Or Disable Extension Loading +*/ +int sqlite3_enable_load_extension(sqlite3 *db, int onoff); + +/** +** CAPI3REF: Automatically Load Statically Linked Extensions +*/ +int sqlite3_auto_extension(void function () xEntryPoint); + +/** +** CAPI3REF: Cancel Automatic Extension Loading +*/ +int sqlite3_cancel_auto_extension(void function() xEntryPoint); + +/** +** CAPI3REF: Reset Automatic Extension Loading +*/ +void sqlite3_reset_auto_extension(); + +/** +** The interface to the virtual-table mechanism is currently considered +** to be experimental. The interface might change in incompatible ways. +** If this is a problem for you, do not use the interface at this time. +** +** When the virtual-table mechanism stabilizes, we will declare the +** interface fixed, support it indefinitely, and remove this comment. +*/ + +/** +** CAPI3REF: Virtual Table Object +*/ + +alias mapFunction = void function (sqlite3_context*,int,sqlite3_value**); + +/// Ditto +struct sqlite3_module +{ + int iVersion; + int function (sqlite3*, void *pAux, + int argc, const char **argv, + sqlite3_vtab **ppVTab, char**) xCreate; + int function (sqlite3*, void *pAux, + int argc, const char **argv, + sqlite3_vtab **ppVTab, char**) xConnect; + int function (sqlite3_vtab *pVTab, sqlite3_index_info*) xBestIndex; + int function (sqlite3_vtab *pVTab) xDisconnect; + int function (sqlite3_vtab *pVTab) xDestroy; + int function (sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor) xOpen; + int function (sqlite3_vtab_cursor*) xClose; + int function (sqlite3_vtab_cursor*, int idxNum, const char *idxStr, + int argc, sqlite3_value **argv) xFilter; + int function (sqlite3_vtab_cursor*) xNext; + int function (sqlite3_vtab_cursor*) xEof; + int function (sqlite3_vtab_cursor*, sqlite3_context*, int) xColumn; + int function (sqlite3_vtab_cursor*, sqlite3_int64 *pRowid) xRowid; + int function (sqlite3_vtab *, int, sqlite3_value **, sqlite3_int64 *) xUpdate; + int function (sqlite3_vtab *pVTab) xBegin; + int function (sqlite3_vtab *pVTab) xSync; + int function (sqlite3_vtab *pVTab) xCommit; + int function (sqlite3_vtab *pVTab) xRollback; + int function (sqlite3_vtab *pVtab, int nArg, const char *zName, + mapFunction*, + void **ppArg) xFindFunction; + int function (sqlite3_vtab *pVtab, const char *zNew) xRename; + int function (sqlite3_vtab *pVTab, int) xSavepoint; + int function (sqlite3_vtab *pVTab, int) xRelease; + int function (sqlite3_vtab *pVTab, int) xRollbackTo; +} + +/** +** CAPI3REF: Virtual Table Indexing Information +*/ +struct sqlite3_index_info +{ + struct sqlite3_index_constraint + { + int iColumn; /** Column on left-hand side of constraint */ + char op; /** Constraint operator */ + char usable; /** True if this constraint is usable */ + int iTermOffset; /** Used internally - xBestIndex should ignore */ + } + struct sqlite3_index_orderby + { + int iColumn; /** Column number */ + char desc; /** True for DESC. False for ASC. */ + } + struct sqlite3_index_constraint_usage + { + int argvIndex; /** if >0, constraint is part of argv to xFilter */ + char omit; /** Do not code a test for this constraint */ + } + /* Inputs */ + int nConstraint; /** Number of entries in aConstraint */ + sqlite3_index_constraint* aConstraint; /** Table of WHERE clause constraints */ + int nOrderBy; /** Number of terms in the ORDER BY clause */ + sqlite3_index_orderby *aOrderBy; /** The ORDER BY clause */ + /* Outputs */ + sqlite3_index_constraint_usage *aConstraintUsage; + int idxNum; /** Number used to identify the index */ + char *idxStr; /** String, possibly obtained from sqlite3_malloc */ + int needToFreeIdxStr; /** Free idxStr using sqlite3_free() if true */ + int orderByConsumed; /** True if output is already ordered */ + double estimatedCost; /** Estimated cost of using this index */ + sqlite3_int64 estimatedRows; + int idxFlags; + sqlite3_uint64 colUsed; +} + +/** +** CAPI3REF: Virtual Table Constraint Operator Codes +*/ +enum +{ + SQLITE_INDEX_SCAN_UNIQUE = 1, + SQLITE_INDEX_CONSTRAINT_EQ = 2, + SQLITE_INDEX_CONSTRAINT_GT = 4, + SQLITE_INDEX_CONSTRAINT_LE = 8, + SQLITE_INDEX_CONSTRAINT_LT = 16, + SQLITE_INDEX_CONSTRAINT_GE = 32, + SQLITE_INDEX_CONSTRAINT_MATCH = 64, + SQLITE_INDEX_CONSTRAINT_LIKE = 65, + SQLITE_INDEX_CONSTRAINT_GLOB = 66, + SQLITE_INDEX_CONSTRAINT_REGEXP = 67, +} + +/** +** CAPI3REF: Register A Virtual Table Implementation +*/ +int sqlite3_create_module( + sqlite3 *db, /* SQLite connection to register module with */ + const(char)*zName, /* Name of the module */ + const(sqlite3_module)*p, /* Methods for the module */ + void *pClientData /* Client data for xCreate/xConnect */ +); +/// Ditto +int sqlite3_create_module_v2( + sqlite3 *db, /* SQLite connection to register module with */ + const(char)*zName, /* Name of the module */ + const(sqlite3_module)*p, /* Methods for the module */ + void *pClientData, /* Client data for xCreate/xConnect */ + void function (void*) xDestroy /* Module destructor function */ +); + +/** +** CAPI3REF: Virtual Table Instance Object +*/ +struct sqlite3_vtab +{ + const(sqlite3_module)*pModule; /** The module for this virtual table */ + int nRef; /** NO LONGER USED */ + char *zErrMsg; /** Error message from sqlite3_mprintf() */ + /* Virtual table implementations will typically add additional fields */ +} + +/** +** CAPI3REF: Virtual Table Cursor Object +*/ +struct sqlite3_vtab_cursor +{ + sqlite3_vtab *pVtab; /** Virtual table of this cursor */ + /* Virtual table implementations will typically add additional fields */ +} + +/** +** CAPI3REF: Declare The Schema Of A Virtual Table +*/ +int sqlite3_declare_vtab(sqlite3*, const char *zSQL); + +/** +** CAPI3REF: Overload A Function For A Virtual Table +*/ +int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg); + +/** +** The interface to the virtual-table mechanism defined above (back up +** to a comment remarkably similar to this one) is currently considered +** to be experimental. The interface might change in incompatible ways. +** If this is a problem for you, do not use the interface at this time. +** +** When the virtual-table mechanism stabilizes, we will declare the +** interface fixed, support it indefinitely, and remove this comment. +*/ + +/* +** CAPI3REF: A Handle To An Open BLOB +*/ +struct sqlite3_blob; + +/** +** CAPI3REF: Open A BLOB For Incremental I/O +*/ +int sqlite3_blob_open( + sqlite3*, + const(char)* zDb, + const(char)* zTable, + const(char)* zColumn, + sqlite3_int64 iRow, + int flags, + sqlite3_blob **ppBlob +); + +/** +** CAPI3REF: Move a BLOB Handle to a New Row +*/ +int sqlite3_blob_reopen(sqlite3_blob *, sqlite3_int64); + +/** +** CAPI3REF: Close A BLOB Handle +*/ +int sqlite3_blob_close(sqlite3_blob *); + +/** +** CAPI3REF: Return The Size Of An Open BLOB +*/ +int sqlite3_blob_bytes(sqlite3_blob *); + +/** +** CAPI3REF: Read Data From A BLOB Incrementally +*/ +int sqlite3_blob_read(sqlite3_blob *, void *Z, int N, int iOffset); + +/** +** CAPI3REF: Write Data Into A BLOB Incrementally +*/ +int sqlite3_blob_write(sqlite3_blob *, const void *z, int n, int iOffset); + +/** +** CAPI3REF: Virtual File System Objects +*/ +sqlite3_vfs *sqlite3_vfs_find(const char *zVfsName); +/// Ditto +int sqlite3_vfs_register(sqlite3_vfs*, int makeDflt); +/// Ditto +int sqlite3_vfs_unregister(sqlite3_vfs*); + +/** +** CAPI3REF: Mutexes +*/ +sqlite3_mutex *sqlite3_mutex_alloc(int); +/// Ditto +void sqlite3_mutex_free(sqlite3_mutex*); +/// Ditto +void sqlite3_mutex_enter(sqlite3_mutex*); +/// Ditto +int sqlite3_mutex_try(sqlite3_mutex*); +/// Ditto +void sqlite3_mutex_leave(sqlite3_mutex*); + +/** +** CAPI3REF: Mutex Methods Object +*/ +struct sqlite3_mutex_methods +{ + int function () xMutexInit; + int function () xMutexEnd; + sqlite3_mutex* function (int) xMutexAlloc; + void function (sqlite3_mutex *) xMutexFree; + void function (sqlite3_mutex *) xMutexEnter; + int function (sqlite3_mutex *) xMutexTry; + void function (sqlite3_mutex *) xMutexLeave; + int function (sqlite3_mutex *) xMutexHeld; + int function (sqlite3_mutex *) xMutexNotheld; +} + +/** +** CAPI3REF: Mutex Verification Routines +*/ + +//#ifndef NDEBUG +int sqlite3_mutex_held(sqlite3_mutex*); +/// Ditto +int sqlite3_mutex_notheld(sqlite3_mutex*); +//#endif + +/** +** CAPI3REF: Mutex Types +*/ +enum +{ + SQLITE_MUTEX_FAST = 0, + SQLITE_MUTEX_RECURSIVE = 1, + SQLITE_MUTEX_STATIC_MASTER = 2, + SQLITE_MUTEX_STATIC_MEM = 3, /** sqlite3_malloc() */ + SQLITE_MUTEX_STATIC_MEM2 = 4, /** NOT USED */ + SQLITE_MUTEX_STATIC_OPEN = 4, /** sqlite3BtreeOpen() */ + SQLITE_MUTEX_STATIC_PRNG = 5, /** sqlite3_random() */ + SQLITE_MUTEX_STATIC_LRU = 6, /** lru page list */ + SQLITE_MUTEX_STATIC_LRU2 = 7, /** NOT USED */ + SQLITE_MUTEX_STATIC_PMEM = 7, /** sqlite3PageMalloc() */ + SQLITE_MUTEX_STATIC_APP1 = 8, /** For use by application */ + SQLITE_MUTEX_STATIC_APP2 = 9, /** For use by application */ + SQLITE_MUTEX_STATIC_APP3 = 10, /** For use by application */ + SQLITE_MUTEX_STATIC_VFS1 = 11, /** For use by built-in VFS */ + SQLITE_MUTEX_STATIC_VFS2 = 12, /** For use by extension VFS */ + SQLITE_MUTEX_STATIC_VFS3 = 13, /** For use by application VFS */ +} + +/** +** CAPI3REF: Retrieve the mutex for a database connection +*/ +sqlite3_mutex *sqlite3_db_mutex(sqlite3*); + +/** +** CAPI3REF: Low-Level Control Of Database Files +*/ +int sqlite3_file_control(sqlite3*, const char *zDbName, int op, void*); + +/** +** CAPI3REF: Testing Interface +*/ +int sqlite3_test_control(int op, ...); + +/** +** CAPI3REF: Testing Interface Operation Codes +*/ +enum +{ + SQLITE_TESTCTRL_FIRST = 5, + SQLITE_TESTCTRL_PRNG_SAVE = 5, + SQLITE_TESTCTRL_PRNG_RESTORE = 6, + SQLITE_TESTCTRL_PRNG_RESET = 7, + SQLITE_TESTCTRL_BITVEC_TEST = 8, + SQLITE_TESTCTRL_FAULT_INSTALL = 9, + SQLITE_TESTCTRL_BENIGN_MALLOC_HOOKS = 10, + SQLITE_TESTCTRL_PENDING_BYTE = 11, + SQLITE_TESTCTRL_ASSERT = 12, + SQLITE_TESTCTRL_ALWAYS = 13, + SQLITE_TESTCTRL_RESERVE = 14, + SQLITE_TESTCTRL_OPTIMIZATIONS = 15, + SQLITE_TESTCTRL_ISKEYWORD = 16, + SQLITE_TESTCTRL_SCRATCHMALLOC = 17, + SQLITE_TESTCTRL_LOCALTIME_FAULT = 18, + SQLITE_TESTCTRL_EXPLAIN_STMT = 19, + SQLITE_TESTCTRL_NEVER_CORRUPT = 20, + SQLITE_TESTCTRL_VDBE_COVERAGE = 21, + SQLITE_TESTCTRL_BYTEORDER = 22, + SQLITE_TESTCTRL_ISINIT = 23, + SQLITE_TESTCTRL_SORTER_MMAP = 24, + SQLITE_TESTCTRL_IMPOSTER = 25, + SQLITE_TESTCTRL_LAST = 25, +} + +/** +** CAPI3REF: SQLite Runtime Status +*/ +int sqlite3_status(int op, int *pCurrent, int *pHighwater, int resetFlag); +/// Ditto +int sqlite3_status64(int op, long *pCurrent, long *pHighwater, int resetFlag); + +/** +** CAPI3REF: Status Parameters +*/ +enum +{ + SQLITE_STATUS_MEMORY_USED = 0, + SQLITE_STATUS_PAGECACHE_USED = 1, + SQLITE_STATUS_PAGECACHE_OVERFLOW = 2, + SQLITE_STATUS_SCRATCH_USED = 3, + SQLITE_STATUS_SCRATCH_OVERFLOW = 4, + SQLITE_STATUS_MALLOC_SIZE = 5, + SQLITE_STATUS_PARSER_STACK = 6, + SQLITE_STATUS_PAGECACHE_SIZE = 7, + SQLITE_STATUS_SCRATCH_SIZE = 8, + SQLITE_STATUS_MALLOC_COUNT = 9 +} + +/** +** CAPI3REF: Database Connection Status +*/ +int sqlite3_db_status(sqlite3*, int op, int *pCur, int *pHiwtr, int resetFlg); + +/** +** CAPI3REF: Status Parameters for database connections +*/ +enum +{ + SQLITE_DBSTATUS_LOOKASIDE_USED = 0, + SQLITE_DBSTATUS_CACHE_USED = 1, + SQLITE_DBSTATUS_SCHEMA_USED = 2, + SQLITE_DBSTATUS_STMT_USED = 3, + SQLITE_DBSTATUS_LOOKASIDE_HIT = 4, + SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE = 5, + SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL = 6, + SQLITE_DBSTATUS_CACHE_HIT = 7, + SQLITE_DBSTATUS_CACHE_MISS = 8, + SQLITE_DBSTATUS_CACHE_WRITE = 9, + SQLITE_DBSTATUS_DEFERRED_FKS = 10, + SQLITE_DBSTATUS_MAX = 10 /** Largest defined DBSTATUS */ +} + +/** +** CAPI3REF: Prepared Statement Status +*/ +int sqlite3_stmt_status(sqlite3_stmt*, int op,int resetFlg); + +/** +** CAPI3REF: Status Parameters for prepared statements +*/ +enum +{ + SQLITE_STMTSTATUS_FULLSCAN_STEP = 1, + SQLITE_STMTSTATUS_SORT = 2, + SQLITE_STMTSTATUS_AUTOINDEX = 3, + SQLITE_STMTSTATUS_VM_STEP = 4 +} + +/** +** CAPI3REF: Custom Page Cache Object +*/ +struct sqlite3_pcache; + +/** +** CAPI3REF: Custom Page Cache Object +*/ +struct sqlite3_pcache_page +{ + void *pBuf; /* The content of the page */ + void *pExtra; /* Extra information associated with the page */ +} + +/** +** CAPI3REF: Application Defined Page Cache. +*/ +struct sqlite3_pcache_methods2 +{ + int iVersion; + void *pArg; + int function(void*) xInit; + void function(void*) xShutdown; + sqlite3_pcache * function(int szPage, int szExtra, int bPurgeable) xCreate; + void function(sqlite3_pcache*, int nCachesize) xCachesize; + int function(sqlite3_pcache*) xPagecount; + sqlite3_pcache_page * function(sqlite3_pcache*, uint key, int createFlag) xFetch; + void function(sqlite3_pcache*, sqlite3_pcache_page*, int discard) xUnpin; + void function(sqlite3_pcache*, sqlite3_pcache_page*, + uint oldKey, uint newKey) xRekey; + void function(sqlite3_pcache*, uint iLimit) xTruncate; + void function(sqlite3_pcache*) xDestroy; + void function(sqlite3_pcache*) xShrink; +} + +struct sqlite3_pcache_methods +{ + void *pArg; + int function (void*) xInit; + void function (void*) xShutdown; + sqlite3_pcache* function (int szPage, int bPurgeable) xCreate; + void function (sqlite3_pcache*, int nCachesize) xCachesize; + int function (sqlite3_pcache*) xPagecount; + void* function (sqlite3_pcache*, uint key, int createFlag) xFetch; + void function (sqlite3_pcache*, void*, int discard) xUnpin; + void function (sqlite3_pcache*, void*, uint oldKey, uint newKey) xRekey; + void function (sqlite3_pcache*, uint iLimit) xTruncate; + void function (sqlite3_pcache*) xDestroy; +} + +/** +** CAPI3REF: Online Backup Object +*/ +struct sqlite3_backup; + +/** +** CAPI3REF: Online Backup API. +*/ +sqlite3_backup *sqlite3_backup_init( + sqlite3 *pDest, /** Destination database handle */ + const(char)*zDestName, /** Destination database name */ + sqlite3 *pSource, /** Source database handle */ + const(char)*zSourceName /** Source database name */ +); +/// Ditto +int sqlite3_backup_step(sqlite3_backup *p, int nPage); +/// Ditto +int sqlite3_backup_finish(sqlite3_backup *p); +/// Ditto +int sqlite3_backup_remaining(sqlite3_backup *p); +/// Ditto +int sqlite3_backup_pagecount(sqlite3_backup *p); + +/** +** CAPI3REF: Unlock Notification +*/ +int sqlite3_unlock_notify( + sqlite3 *pBlocked, /** Waiting connection */ + void function (void **apArg, int nArg) xNotify, /** Callback function to invoke */ + void *pNotifyArg /** Argument to pass to xNotify */ +); + +/** +** CAPI3REF: String Comparison +*/ +int sqlite3_stricmp(const char * , const char * ); +int sqlite3_strnicmp(const char * , const char * , int); + +/* +** CAPI3REF: String Globbing +* +*/ +int sqlite3_strglob(const(char)* zGlob, const(char)* zStr); + +/* +** CAPI3REF: String LIKE Matching +*/ +int sqlite3_strlike(const(char)* zGlob, const(char)* zStr, uint cEsc); + +/** +** CAPI3REF: Error Logging Interface +*/ +void sqlite3_log(int iErrCode, const char *zFormat, ...); + +/** +** CAPI3REF: Write-Ahead Log Commit Hook +*/ +void *sqlite3_wal_hook( + sqlite3*, + int function (void *,sqlite3*,const char*,int), + void* +); + +/** +** CAPI3REF: Configure an auto-checkpoint +*/ +int sqlite3_wal_autocheckpoint(sqlite3 *db, int N); + +/** +** CAPI3REF: Checkpoint a database +*/ +int sqlite3_wal_checkpoint(sqlite3 *db, const char *zDb); + +/** +** CAPI3REF: Checkpoint a database +*/ +int sqlite3_wal_checkpoint_v2( + sqlite3 *db, /** Database handle */ + const(char)*zDb, /** Name of attached database (or NULL) */ + int eMode, /** SQLITE_CHECKPOINT_* value */ + int *pnLog, /** OUT: Size of WAL log in frames */ + int *pnCkpt /** OUT: Total number of frames checkpointed */ +); + +/** +** CAPI3REF: Checkpoint operation parameters +*/ +enum +{ + SQLITE_CHECKPOINT_PASSIVE = 0, + SQLITE_CHECKPOINT_FULL = 1, + SQLITE_CHECKPOINT_RESTART = 2, + SQLITE_CHECKPOINT_TRUNCATE = 3, +} + +/* +** CAPI3REF: Virtual Table Interface Configuration +*/ +int sqlite3_vtab_config(sqlite3*, int op, ...); + +/** +** CAPI3REF: Virtual Table Configuration Options +*/ +enum SQLITE_VTAB_CONSTRAINT_SUPPORT = 1; + +/* +** 2010 August 30 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. +** +************************************************************************* +*/ + +//#ifndef _SQLITE3RTREE_H_ +//#define _SQLITE3RTREE_H_ + + +/* +** CAPI3REF: Determine The Virtual Table Conflict Policy +*/ +int sqlite3_vtab_on_conflict(sqlite3 *); + +/* +** CAPI3REF: Conflict resolution modes +*/ +enum +{ + SQLITE_ROLLBACK = 1, + SQLITE_FAIL = 3, + SQLITE_REPLACE = 5 +} + +/* +** CAPI3REF: Prepared Statement Scan Status Opcodes +*/ +enum +{ + SQLITE_SCANSTAT_NLOOP = 0, + SQLITE_SCANSTAT_NVISIT = 1, + SQLITE_SCANSTAT_EST = 2, + SQLITE_SCANSTAT_NAME = 3, + SQLITE_SCANSTAT_EXPLAIN = 4, + SQLITE_SCANSTAT_SELECTID = 5, +} + +/* +** CAPI3REF: Prepared Statement Scan Status +*/ +int sqlite3_stmt_scanstatus(sqlite3_stmt *pStmt, int idx, int iScanStatusOp, void *pOut); + +/* +** CAPI3REF: Zero Scan-Status Counters +*/ +void sqlite3_stmt_scanstatus_reset(sqlite3_stmt *); + +/* +** CAPI3REF: Flush caches to disk mid-transaction +*/ +int sqlite3_db_cacheflush(sqlite3 *); + +struct sqlite3_snapshot; + +/* +** CAPI3REF: Record A Database Snapshot +*/ +int sqlite3_snapshot_get(sqlite3 *db, char *zSchema, sqlite3_snapshot **ppSnapshot); + +/* +** CAPI3REF: Start a read transaction on an historical snapshot +*/ +int sqlite3_snapshot_open(sqlite3 *db, char *zSchema, sqlite3_snapshot *pSnapshot); + +/* +** CAPI3REF: Destroy a snapshot +*/ +void sqlite3_snapshot_free(sqlite3_snapshot *); + +/** +** Register a geometry callback named zGeom that can be used as part of an +** R-Tree geometry query as follows: +** +** SELECT ... FROM $(LT)rtree$(GT) WHERE $(LT)rtree col$(GT) MATCH $zGeom(... params ...) +*/ +int sqlite3_rtree_geometry_callback( + sqlite3 *db, + const(char)*zGeom, + int function (sqlite3_rtree_geometry *, int nCoord, double *aCoord, int *pRes) xGeom, + void *pContext +); + +/** +** A pointer to a structure of the following type is passed as the first +** argument to callbacks registered using rtree_geometry_callback(). +*/ +struct sqlite3_rtree_geometry +{ + void *pContext; /** Copy of pContext passed to s_r_g_c() */ + int nParam; /** Size of array aParam[] */ + double *aParam; /** Parameters passed to SQL geom function */ + void *pUser; /** Callback implementation user data */ + void function (void *) xDelUser; /** Called by SQLite to clean up pUser */ +} + +int sqlite3_rtree_query_callback( + sqlite3 *db, + const(char)* zQueryFunc, + int function(sqlite3_rtree_query_info*) xQueryFunc, + void *pContext, + void function(void*) xDestructor +); + +struct sqlite3_rtree_query_info +{ + void *pContext; /* pContext from when function registered */ + int nParam; /* Number of function parameters */ + double*aParam; /* value of function parameters */ + void *pUser; /* callback can use this, if desired */ + void function(void*) xDelUser; /* function to free pUser */ + double*aCoord; /* Coordinates of node or entry to check */ + uint *anQueue; /* Number of pending entries in the queue */ + int nCoord; /* Number of coordinates */ + int iLevel; /* Level of current node or entry */ + int mxLevel; /* The largest iLevel value in the tree */ + sqlite3_int64 iRowid; /* Rowid for current entry */ + double rParentScore; /* Score of parent node */ + int eParentWithin; /* Visibility of parent node */ + int eWithin; /* OUT: Visiblity */ + double rScore; /* OUT: Write the score here */ + sqlite3_value **apSqlParam; /* Original SQL values of parameters */ +} + +enum +{ + NOT_WITHIN = 0, + PARTLY_WITHIN = 1, + FULLY_WITHIN = 2 +} + +/****************************************************************************** +** Interfaces to extend FTS5. +*/ +struct Fts5Context; +/// Ditto +alias fts5_extension_function = void function( + const Fts5ExtensionApi *pApi, + Fts5Context *pFts, + sqlite3_context *pCtx, + int nVal, + sqlite3_value **apVal +); +/// Ditto +struct Fts5PhraseIter +{ + const(ubyte) *a; + const(ubyte) *b; +} +/// Ditto +struct Fts5ExtensionApi +{ + int iVersion; + void* function(Fts5Context*) xUserData; + int function(Fts5Context*) xColumnCount; + int function(Fts5Context*, sqlite3_int64 *pnRow) xRowCount; + int function(Fts5Context*, int iCol, sqlite3_int64 *pnToken) xColumnTotalSize; + int function(Fts5Context*, + const char *pText, int nText, + void *pCtx, + int function(void*, int, const char*, int, int, int) xToken + ) xTokenize; + int function(Fts5Context*) xPhraseCount; + int function(Fts5Context*, int iPhrase) xPhraseSize; + int function(Fts5Context*, int *pnInst) xInstCount; + int function(Fts5Context*, int iIdx, int *piPhrase, int *piCol, int *piOff) xInst; + sqlite3_int64 function(Fts5Context*) xRowid; + int function(Fts5Context*, int iCol, const char **pz, int *pn) xColumnText; + int function(Fts5Context*, int iCol, int *pnToken) xColumnSize; + int function(Fts5Context*, int iPhrase, void *pUserData, + int function(const Fts5ExtensionApi*,Fts5Context*,void*) + ) xQueryPhrase; + int function(Fts5Context*, void *pAux, void function(void*) xDelete) xSetAuxdata; + void* function(Fts5Context*, int bClear) xGetAuxdata; + void function(Fts5Context*, int iPhrase, Fts5PhraseIter*, int*, int*) xPhraseFirst; + void function(Fts5Context*, Fts5PhraseIter*, int *piCol, int *piOff) xPhraseNext; +} +/// Ditto +struct Fts5Tokenizer; +struct fts5_tokenizer +{ + int function(void*, const char **azArg, int nArg, Fts5Tokenizer **ppOut) xCreate; + void function(Fts5Tokenizer*) xDelete; + int function(Fts5Tokenizer*, + void *pCtx, + int flags, + const char *pText, int nText, + int function( + void *pCtx, + int tflags, + const char *pToken, + int nToken, + int iStart, + int iEnd + ) xToken + ) xTokenize; +} +/// Ditto +enum FTS5_TOKENIZE_QUERY = 0x0001; +/// Ditto +enum FTS5_TOKENIZE_PREFIX = 0x0002; +/// Ditto +enum FTS5_TOKENIZE_DOCUMENT = 0x0004; +/// Ditto +enum FTS5_TOKENIZE_AUX = 0x0008; +/// Ditto +enum FTS5_TOKEN_COLOCATED = 0x0001; +/// Ditto +struct fts5_api +{ + int iVersion; + + int function( + fts5_api *pApi, + const char *zName, + void *pContext, + fts5_tokenizer *pTokenizer, + void function(void*) xDestroy + ) xCreateTokenizer; + + int function( + fts5_api *pApi, + const char *zName, + void **ppContext, + fts5_tokenizer *pTokenizer + ) xFindTokenizer; + + int function( + fts5_api *pApi, + const char *zName, + void *pContext, + fts5_extension_function xFunction, + void function(void*) xDestroy + ) xCreateFunction; +} diff --git a/libphobos/src/etc/c/zlib.d b/libphobos/src/etc/c/zlib.d new file mode 100644 index 0000000..b3e9783 --- /dev/null +++ b/libphobos/src/etc/c/zlib.d @@ -0,0 +1,1788 @@ +/* zlib.d: modified from zlib.h by Walter Bright */ +/* updated from 1.2.1 to 1.2.3 by Thomas Kuehne */ +/* updated from 1.2.3 to 1.2.8 by Dmitry Atamanov */ +/* updated from 1.2.8 to 1.2.11 by Iain Buclaw */ + +module etc.c.zlib; + +import core.stdc.config; + +/* zlib.h -- interface of the 'zlib' general purpose compression library + version 1.2.11, January 15th, 2017 + + Copyright (C) 1995-2017 Jean-loup Gailly and Mark Adler + + 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. + + Jean-loup Gailly Mark Adler + jloup@gzip.org madler@alumni.caltech.edu + + + The data format used by the zlib library is described by RFCs (Request for + Comments) 1950 to 1952 in the files http://tools.ietf.org/html/rfc1950 + (zlib format), rfc1951 (deflate format) and rfc1952 (gzip format). +*/ + +nothrow: +extern (C): + +const char[] ZLIB_VERSION = "1.2.11"; +const ZLIB_VERNUM = 0x12b0; + +/* + The 'zlib' compression library provides in-memory compression and + decompression functions, including integrity checks of the uncompressed data. + This version of the library supports only one compression method (deflation) + but other algorithms will be added later and will have the same stream + interface. + + Compression can be done in a single step if the buffers are large enough, + or can be done by repeated calls of the compression function. In the latter + case, the application must provide more input and/or consume the output + (providing more output space) before each call. + + The compressed data format used by default by the in-memory functions is + the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped + around a deflate stream, which is itself documented in RFC 1951. + + The library also supports reading and writing files in gzip (.gz) format + with an interface similar to that of stdio using the functions that start + with "gz". The gzip format is different from the zlib format. gzip is a + gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. + + This library can optionally read and write gzip and raw deflate streams in + memory as well. + + The zlib format was designed to be compact and fast for use in memory + and on communications channels. The gzip format was designed for single- + file compression on file systems, has a larger header than zlib to maintain + directory information, and uses a different, slower check method than zlib. + + The library does not install any signal handler. The decoder checks + the consistency of the compressed data, so the library should never crash + even in the case of corrupted input. +*/ + +alias alloc_func = void* function (void* opaque, uint items, uint size); +alias free_func = void function (void* opaque, void* address); + +struct z_stream +{ + const(ubyte)* next_in; /* next input byte */ + uint avail_in; /* number of bytes available at next_in */ + c_ulong total_in; /* total nb of input bytes read so far */ + + ubyte* next_out; /* next output byte will go here */ + uint avail_out; /* remaining free space at next_out */ + c_ulong total_out; /* total nb of bytes output so far */ + + const(char)* msg; /* last error message, NULL if no error */ + void* state; /* not visible by applications */ + + alloc_func zalloc; /* used to allocate the internal state */ + free_func zfree; /* used to free the internal state */ + void* opaque; /* private data object passed to zalloc and zfree */ + + int data_type; /* best guess about the data type: binary or text + for deflate, or the decoding state for inflate */ + c_ulong adler; /* Adler-32 or CRC-32 value of the uncompressed data */ + c_ulong reserved; /* reserved for future use */ +} + +alias z_streamp = z_stream*; + +/* + gzip header information passed to and from zlib routines. See RFC 1952 + for more details on the meanings of these fields. +*/ +struct gz_header +{ + int text; /* true if compressed data believed to be text */ + c_ulong time; /* modification time */ + int xflags; /* extra flags (not used when writing a gzip file) */ + int os; /* operating system */ + byte *extra; /* pointer to extra field or Z_NULL if none */ + uint extra_len; /* extra field length (valid if extra != Z_NULL) */ + uint extra_max; /* space at extra (only when reading header) */ + byte* name; /* pointer to zero-terminated file name or Z_NULL */ + uint name_max; /* space at name (only when reading header) */ + byte* comment; /* pointer to zero-terminated comment or Z_NULL */ + uint comm_max; /* space at comment (only when reading header) */ + int hcrc; /* true if there was or will be a header crc */ + int done; /* true when done reading gzip header (not used + when writing a gzip file) */ +} + +alias gz_headerp = gz_header*; + +/* + The application must update next_in and avail_in when avail_in has dropped + to zero. It must update next_out and avail_out when avail_out has dropped + to zero. The application must initialize zalloc, zfree and opaque before + calling the init function. All other fields are set by the compression + library and must not be updated by the application. + + The opaque value provided by the application will be passed as the first + parameter for calls of zalloc and zfree. This can be useful for custom + memory management. The compression library attaches no meaning to the + opaque value. + + zalloc must return Z_NULL if there is not enough memory for the object. + If zlib is used in a multi-threaded application, zalloc and zfree must be + thread safe. In that case, zlib is thread-safe. When zalloc and zfree are + Z_NULL on entry to the initialization function, they are set to internal + routines that use the standard library functions malloc() and free(). + + On 16-bit systems, the functions zalloc and zfree must be able to allocate + exactly 65536 bytes, but will not be required to allocate more than this if + the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers + returned by zalloc for objects of exactly 65536 bytes *must* have their + offset normalized to zero. The default allocation function provided by this + library ensures this (see zutil.c). To reduce memory requirements and avoid + any allocation of 64K objects, at the expense of compression ratio, compile + the library with -DMAX_WBITS=14 (see zconf.h). + + The fields total_in and total_out can be used for statistics or progress + reports. After compression, total_in holds the total size of the + uncompressed data and may be saved for use by the decompressor (particularly + if the decompressor wants to decompress everything in a single step). +*/ + + /* constants */ + +enum +{ + Z_NO_FLUSH = 0, + Z_PARTIAL_FLUSH = 1, /* will be removed, use Z_SYNC_FLUSH instead */ + Z_SYNC_FLUSH = 2, + Z_FULL_FLUSH = 3, + Z_FINISH = 4, + Z_BLOCK = 5, + Z_TREES = 6, +} +/* Allowed flush values; see deflate() and inflate() below for details */ + +enum +{ + Z_OK = 0, + Z_STREAM_END = 1, + Z_NEED_DICT = 2, + Z_ERRNO = -1, + Z_STREAM_ERROR = -2, + Z_DATA_ERROR = -3, + Z_MEM_ERROR = -4, + Z_BUF_ERROR = -5, + Z_VERSION_ERROR = -6, +} +/* Return codes for the compression/decompression functions. Negative + * values are errors, positive values are used for special but normal events. + */ + +enum +{ + Z_NO_COMPRESSION = 0, + Z_BEST_SPEED = 1, + Z_BEST_COMPRESSION = 9, + Z_DEFAULT_COMPRESSION = -1, +} +/* compression levels */ + +enum +{ + Z_FILTERED = 1, + Z_HUFFMAN_ONLY = 2, + Z_RLE = 3, + Z_FIXED = 4, + Z_DEFAULT_STRATEGY = 0, +} +/* compression strategy; see deflateInit2() below for details */ + +enum +{ + Z_BINARY = 0, + Z_TEXT = 1, + Z_UNKNOWN = 2, + + Z_ASCII = Z_TEXT +} +/* Possible values of the data_type field for deflate() */ + +enum +{ + Z_DEFLATED = 8, +} +/* The deflate compression method (the only one supported in this version) */ + +const int Z_NULL = 0; /* for initializing zalloc, zfree, opaque */ + + /* basic functions */ + +const(char)* zlibVersion(); +/* The application can compare zlibVersion and ZLIB_VERSION for consistency. + If the first character differs, the library code actually used is not + compatible with the zlib.h header file used by the application. This check + is automatically made by deflateInit and inflateInit. + */ + +int deflateInit(z_streamp strm, int level) +{ + return deflateInit_(strm, level, ZLIB_VERSION.ptr, z_stream.sizeof); +} +/* + Initializes the internal stream state for compression. The fields + zalloc, zfree and opaque must be initialized before by the caller. If + zalloc and zfree are set to Z_NULL, deflateInit updates them to use default + allocation functions. + + The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: + 1 gives best speed, 9 gives best compression, 0 gives no compression at all + (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION + requests a default compromise between speed and compression (currently + equivalent to level 6). + + deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if level is not a valid compression level, or + Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible + with the version assumed by the caller (ZLIB_VERSION). msg is set to null + if there is no error message. deflateInit does not perform any compression: + this will be done by deflate(). +*/ + + +int deflate(z_streamp strm, int flush); +/* + deflate compresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce + some output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. deflate performs one or both of the + following actions: + + - Compress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), next_in and avail_in are updated and + processing will resume at this point for the next call of deflate(). + + - Generate more output starting at next_out and update next_out and avail_out + accordingly. This action is forced if the parameter flush is non zero. + Forcing flush frequently degrades the compression ratio, so this parameter + should be set only when necessary. Some output may be provided even if + flush is zero. + + Before the call of deflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming more + output, and updating avail_in or avail_out accordingly; avail_out should + never be zero before the call. The application can consume the compressed + output when it wants, for example when the output buffer is full (avail_out + == 0), or after each call of deflate(). If deflate returns Z_OK and with + zero avail_out, it must be called again after making room in the output + buffer because there might be more output pending. See deflatePending(), + which can be used if desired to determine whether or not there is more ouput + in that case. + + Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to + decide how much data to accumulate before producing output, in order to + maximize compression. + + If the parameter flush is set to Z_SYNC_FLUSH, all pending output is + flushed to the output buffer and the output is aligned on a byte boundary, so + that the decompressor can get all input data available so far. (In + particular avail_in is zero after the call if enough output space has been + provided before the call.) Flushing may degrade compression for some + compression algorithms and so it should be used only when necessary. This + completes the current deflate block and follows it with an empty stored block + that is three bits plus filler bits to the next byte, followed by four bytes + (00 00 ff ff). + + If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the + output buffer, but the output is not aligned to a byte boundary. All of the + input data so far will be available to the decompressor, as for Z_SYNC_FLUSH. + This completes the current deflate block and follows it with an empty fixed + codes block that is 10 bits long. This assures that enough bytes are output + in order for the decompressor to finish the block before the empty fixed + codes block. + + If flush is set to Z_BLOCK, a deflate block is completed and emitted, as + for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to + seven bits of the current block are held to be written as the next byte after + the next deflate block is completed. In this case, the decompressor may not + be provided enough bits at this point in order to complete decompression of + the data provided so far to the compressor. It may need to wait for the next + block to be emitted. This is for advanced applications that need to control + the emission of deflate blocks. + + If flush is set to Z_FULL_FLUSH, all output is flushed as with + Z_SYNC_FLUSH, and the compression state is reset so that decompression can + restart from this point if previous compressed data has been damaged or if + random access is desired. Using Z_FULL_FLUSH too often can seriously degrade + compression. + + If deflate returns with avail_out == 0, this function must be called again + with the same value of the flush parameter and more output space (updated + avail_out), until the flush is complete (deflate returns with non-zero + avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that + avail_out is greater than six to avoid repeated flush markers due to + avail_out == 0 on return. + + If the parameter flush is set to Z_FINISH, pending input is processed, + pending output is flushed and deflate returns with Z_STREAM_END if there was + enough output space. If deflate returns with Z_OK or Z_BUF_ERROR, this + function must be called again with Z_FINISH and more output space (updated + avail_out) but no more input data, until it returns with Z_STREAM_END or an + error. After deflate has returned Z_STREAM_END, the only possible operations + on the stream are deflateReset or deflateEnd. + + Z_FINISH can be used in the first deflate call after deflateInit if all the + compression is to be done in a single step. In order to complete in one + call, avail_out must be at least the value returned by deflateBound (see + below). Then deflate is guaranteed to return Z_STREAM_END. If not enough + output space is provided, deflate will not return Z_STREAM_END, and it must + be called again as described above. + + deflate() sets strm->adler to the Adler-32 checksum of all input read + so far (that is, total_in bytes). If a gzip stream is being generated, then + strm->adler will be the CRC-32 checksum of the input read so far. (See + deflateInit2 below.) + + deflate() may update strm->data_type if it can make a good guess about + the input data type (Z_BINARY or Z_TEXT). If in doubt, the data is + considered binary. This field is only for information purposes and does not + affect the compression algorithm in any manner. + + deflate() returns Z_OK if some progress has been made (more input + processed or more output produced), Z_STREAM_END if all input has been + consumed and all output has been produced (only when flush is set to + Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example + if next_in or next_out was Z_NULL or the state was inadvertently written over + by the application), or Z_BUF_ERROR if no progress is possible (for example + avail_in or avail_out was zero). Note that Z_BUF_ERROR is not fatal, and + deflate() can be called again with more input and more output space to + continue compressing. +*/ + + +int deflateEnd(z_streamp strm); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any pending + output. + + deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the + stream state was inconsistent, Z_DATA_ERROR if the stream was freed + prematurely (some input or output was discarded). In the error case, msg + may be set but then points to a static string (which must not be + deallocated). +*/ + + +int inflateInit(z_streamp strm) +{ + return inflateInit_(strm, ZLIB_VERSION.ptr, z_stream.sizeof); +} +/* + Initializes the internal stream state for decompression. The fields + next_in, avail_in, zalloc, zfree and opaque must be initialized before by + the caller. In the current version of inflate, the provided input is not + read or consumed. The allocation of a sliding window will be deferred to + the first call of inflate (if the decompression does not complete on the + first call). If zalloc and zfree are set to Z_NULL, inflateInit updates + them to use default allocation functions. + + inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the + version assumed by the caller, or Z_STREAM_ERROR if the parameters are + invalid, such as a null pointer to the structure. msg is set to null if + there is no error message. inflateInit does not perform any decompression. + Actual decompression will be done by inflate(). So next_in, and avail_in, + next_out, and avail_out are unused and unchanged. The current + implementation of inflateInit() does not process any header information -- + that is deferred until inflate() is called. +*/ + + +int inflate(z_streamp strm, int flush); +/* + inflate decompresses as much data as possible, and stops when the input + buffer becomes empty or the output buffer becomes full. It may introduce + some output latency (reading input without producing any output) except when + forced to flush. + + The detailed semantics are as follows. inflate performs one or both of the + following actions: + + - Decompress more input starting at next_in and update next_in and avail_in + accordingly. If not all input can be processed (because there is not + enough room in the output buffer), then next_in and avail_in are updated + accordingly, and processing will resume at this point for the next call of + inflate(). + + - Generate more output starting at next_out and update next_out and avail_out + accordingly. inflate() provides as much output as possible, until there is + no more input data or no more space in the output buffer (see below about + the flush parameter). + + Before the call of inflate(), the application should ensure that at least + one of the actions is possible, by providing more input and/or consuming more + output, and updating the next_* and avail_* values accordingly. If the + caller of inflate() does not provide both available input and available + output space, it is possible that there will be no progress made. The + application can consume the uncompressed output when it wants, for example + when the output buffer is full (avail_out == 0), or after each call of + inflate(). If inflate returns Z_OK and with zero avail_out, it must be + called again after making room in the output buffer because there might be + more output pending. + + The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH, + Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much + output as possible to the output buffer. Z_BLOCK requests that inflate() + stop if and when it gets to the next deflate block boundary. When decoding + the zlib or gzip format, this will cause inflate() to return immediately + after the header and before the first block. When doing a raw inflate, + inflate() will go ahead and process the first block, and will return when it + gets to the end of that block, or when it runs out of data. + + The Z_BLOCK option assists in appending to or combining deflate streams. + To assist in this, on return inflate() always sets strm->data_type to the + number of unused bits in the last byte taken from strm->next_in, plus 64 if + inflate() is currently decoding the last block in the deflate stream, plus + 128 if inflate() returned immediately after decoding an end-of-block code or + decoding the complete header up to just before the first byte of the deflate + stream. The end-of-block will not be indicated until all of the uncompressed + data from that block has been written to strm->next_out. The number of + unused bits may in general be greater than seven, except when bit 7 of + data_type is set, in which case the number of unused bits will be less than + eight. data_type is set as noted here every time inflate() returns for all + flush options, and so can be used to determine the amount of currently + consumed input in bits. + + The Z_TREES option behaves as Z_BLOCK does, but it also returns when the + end of each deflate block header is reached, before any actual data in that + block is decoded. This allows the caller to determine the length of the + deflate block header for later use in random access within a deflate block. + 256 is added to the value of strm->data_type when inflate() returns + immediately after reaching the end of the deflate block header. + + inflate() should normally be called until it returns Z_STREAM_END or an + error. However if all decompression is to be performed in a single step (a + single call of inflate), the parameter flush should be set to Z_FINISH. In + this case all pending input is processed and all pending output is flushed; + avail_out must be large enough to hold all of the uncompressed data for the + operation to complete. (The size of the uncompressed data may have been + saved by the compressor for this purpose.) The use of Z_FINISH is not + required to perform an inflation in one step. However it may be used to + inform inflate that a faster approach can be used for the single inflate() + call. Z_FINISH also informs inflate to not maintain a sliding window if the + stream completes, which reduces inflate's memory footprint. If the stream + does not complete, either because not all of the stream is provided or not + enough output space is provided, then a sliding window will be allocated and + inflate() can be called again to continue the operation as if Z_NO_FLUSH had + been used. + + In this implementation, inflate() always flushes as much output as + possible to the output buffer, and always uses the faster approach on the + first call. So the effects of the flush parameter in this implementation are + on the return value of inflate() as noted below, when inflate() returns early + when Z_BLOCK or Z_TREES is used, and when inflate() avoids the allocation of + memory for a sliding window when Z_FINISH is used. + + If a preset dictionary is needed after this call (see inflateSetDictionary + below), inflate sets strm->adler to the Adler-32 checksum of the dictionary + chosen by the compressor and returns Z_NEED_DICT; otherwise it sets + strm->adler to the Adler-32 checksum of all output produced so far (that is, + total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described + below. At the end of the stream, inflate() checks that its computed Adler-32 + checksum is equal to that saved by the compressor and returns Z_STREAM_END + only if the checksum is correct. + + inflate() can decompress and check either zlib-wrapped or gzip-wrapped + deflate data. The header type is detected automatically, if requested when + initializing with inflateInit2(). Any information contained in the gzip + header is not retained unless inflateGetHeader() is used. When processing + gzip-wrapped deflate data, strm->adler32 is set to the CRC-32 of the output + produced so far. The CRC-32 is checked against the gzip trailer, as is the + uncompressed length, modulo 2^32. + + inflate() returns Z_OK if some progress has been made (more input processed + or more output produced), Z_STREAM_END if the end of the compressed data has + been reached and all uncompressed output has been produced, Z_NEED_DICT if a + preset dictionary is needed at this point, Z_DATA_ERROR if the input data was + corrupted (input stream not conforming to the zlib format or incorrect check + value, in which case strm->msg points to a string with a more specific + error), Z_STREAM_ERROR if the stream structure was inconsistent (for example + next_in or next_out was Z_NULL, or the state was inadvertently written over + by the application), Z_MEM_ERROR if there was not enough memory, Z_BUF_ERROR + if no progress was possible or if there was not enough room in the output + buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and + inflate() can be called again with more input and more output space to + continue decompressing. If Z_DATA_ERROR is returned, the application may + then call inflateSync() to look for a good compression block if a partial + recovery of the data is to be attempted. +*/ + + +int inflateEnd(z_streamp strm); +/* + All dynamically allocated data structures for this stream are freed. + This function discards any unprocessed input and does not flush any pending + output. + + inflateEnd returns Z_OK if success, or Z_STREAM_ERROR if the stream state + was inconsistent. +*/ + + /* Advanced functions */ + +/* + The following functions are needed only in some special applications. +*/ + +int deflateInit2(z_streamp strm, + int level, + int method, + int windowBits, + int memLevel, + int strategy) +{ + return deflateInit2_(strm, level, method, windowBits, memLevel, + strategy, ZLIB_VERSION.ptr, z_stream.sizeof); +} +/* + This is another version of deflateInit with more compression options. The + fields next_in, zalloc, zfree and opaque must be initialized before by the + caller. + + The method parameter is the compression method. It must be Z_DEFLATED in + this version of the library. + + The windowBits parameter is the base two logarithm of the window size + (the size of the history buffer). It should be in the range 8 .. 15 for this + version of the library. Larger values of this parameter result in better + compression at the expense of memory usage. The default value is 15 if + deflateInit is used instead. + + For the current implementation of deflate(), a windowBits value of 8 (a + window size of 256 bytes) is not supported. As a result, a request for 8 + will result in 9 (a 512-byte window). In that case, providing 8 to + inflateInit2() will result in an error when the zlib header with 9 is + checked against the initialization of inflate(). The remedy is to not use 8 + with deflateInit2() with this initialization, or at least in that case use 9 + with inflateInit2(). + + windowBits can also be -8..-15 for raw deflate. In this case, -windowBits + determines the window size. deflate() will then generate raw deflate data + with no zlib header or trailer, and will not compute a check value. + + windowBits can also be greater than 15 for optional gzip encoding. Add + 16 to windowBits to write a simple gzip header and trailer around the + compressed data instead of a zlib wrapper. The gzip header will have no + file name, no extra data, no comment, no modification time (set to zero), no + header crc, and the operating system will be set to the appropriate value, + if the operating system was determined at compile time. If a gzip stream is + being written, strm->adler is a CRC-32 instead of an Adler-32. + + For raw deflate or gzip encoding, a request for a 256-byte window is + rejected as invalid, since only the zlib header provides a means of + transmitting the window size to the decompressor. + + The memLevel parameter specifies how much memory should be allocated + for the internal compression state. memLevel=1 uses minimum memory but is + slow and reduces compression ratio; memLevel=9 uses maximum memory for + optimal speed. The default value is 8. See zconf.h for total memory usage + as a function of windowBits and memLevel. + + The strategy parameter is used to tune the compression algorithm. Use the + value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a + filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no + string match), or Z_RLE to limit match distances to one (run-length + encoding). Filtered data consists mostly of small values with a somewhat + random distribution. In this case, the compression algorithm is tuned to + compress them better. The effect of Z_FILTERED is to force more Huffman + coding and less string matching; it is somewhat intermediate between + Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as + fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The + strategy parameter only affects the compression ratio but not the + correctness of the compressed output even if it is not set appropriately. + Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler + decoder for special applications. + + deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid + method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is + incompatible with the version assumed by the caller (ZLIB_VERSION). msg is + set to null if there is no error message. deflateInit2 does not perform any + compression: this will be done by deflate(). +*/ + +int deflateSetDictionary(z_streamp strm, const(ubyte)* dictionary, uint dictLength); +/* + Initializes the compression dictionary from the given byte sequence + without producing any compressed output. When using the zlib format, this + function must be called immediately after deflateInit, deflateInit2 or + deflateReset, and before any call of deflate. When doing raw deflate, this + function must be called either before any call of deflate, or immediately + after the completion of a deflate block, i.e. after all input has been + consumed and all output has been delivered when using any of the flush + options Z_BLOCK, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH, or Z_FULL_FLUSH. The + compressor and decompressor must use exactly the same dictionary (see + inflateSetDictionary). + + The dictionary should consist of strings (byte sequences) that are likely + to be encountered later in the data to be compressed, with the most commonly + used strings preferably put towards the end of the dictionary. Using a + dictionary is most useful when the data to be compressed is short and can be + predicted with good accuracy; the data can then be compressed better than + with the default empty dictionary. + + Depending on the size of the compression data structures selected by + deflateInit or deflateInit2, a part of the dictionary may in effect be + discarded, for example if the dictionary is larger than the window size + provided in deflateInit or deflateInit2. Thus the strings most likely to be + useful should be put at the end of the dictionary, not at the front. In + addition, the current implementation of deflate will use at most the window + size minus 262 bytes of the provided dictionary. + + Upon return of this function, strm->adler is set to the Adler-32 value + of the dictionary; the decompressor may later use this value to determine + which dictionary has been used by the compressor. (The Adler-32 value + applies to the whole dictionary even if only a subset of the dictionary is + actually used by the compressor.) If a raw deflate was requested, then the + Adler-32 value is not computed and strm->adler is not set. + + deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a + parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is + inconsistent (for example if deflate has already been called for this stream + or if not at a block boundary for raw deflate). deflateSetDictionary does + not perform any compression: this will be done by deflate(). +*/ + +int deflateGetDictionary(z_streamp strm, ubyte *dictionary, uint dictLength); +/* + Returns the sliding dictionary being maintained by deflate. dictLength is + set to the number of bytes in the dictionary, and that many bytes are copied + to dictionary. dictionary must have enough space, where 32768 bytes is + always enough. If deflateGetDictionary() is called with dictionary equal to + Z_NULL, then only the dictionary length is returned, and nothing is copied. + Similary, if dictLength is Z_NULL, then it is not set. + + deflateGetDictionary() may return a length less than the window size, even + when more than the window size in input has been provided. It may return up + to 258 bytes less in that case, due to how zlib's implementation of deflate + manages the sliding window and lookahead for matches, where matches can be + up to 258 bytes long. If the application needs the last window-size bytes of + input, then that would need to be saved by the application outside of zlib. + + deflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the + stream state is inconsistent. +*/ + +int deflateCopy(z_streamp dest, z_streamp source); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when several compression strategies will be + tried, for example when there are several ways of pre-processing the input + data with a filter. The streams that will be discarded should then be freed + by calling deflateEnd. Note that deflateCopy duplicates the internal + compression state which can be quite large, so this strategy is slow and can + consume lots of memory. + + deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being Z_NULL). msg is left unchanged in both source and + destination. +*/ + +int deflateReset(z_streamp strm); +/* + This function is equivalent to deflateEnd followed by deflateInit, but + does not free and reallocate the internal compression state. The stream + will leave the compression level and any other attributes that may have been + set unchanged. + + deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL). +*/ + +int deflateParams(z_streamp strm, int level, int strategy); +/* + Dynamically update the compression level and compression strategy. The + interpretation of level and strategy is as in deflateInit2(). This can be + used to switch between compression and straight copy of the input data, or + to switch to a different kind of input data requiring a different strategy. + If the compression approach (which is a function of the level) or the + strategy is changed, and if any input has been consumed in a previous + deflate() call, then the input available so far is compressed with the old + level and strategy using deflate(strm, Z_BLOCK). There are three approaches + for the compression levels 0, 1 .. 3, and 4 .. 9 respectively. The new level + and strategy will take effect at the next call of deflate(). + + If a deflate(strm, Z_BLOCK) is performed by deflateParams(), and it does + not have enough output space to complete, then the parameter change will not + take effect. In this case, deflateParams() can be called again with the + same parameters and more output space to try again. + + In order to assure a change in the parameters on the first try, the + deflate stream should be flushed using deflate() with Z_BLOCK or other flush + request until strm.avail_out is not zero, before calling deflateParams(). + Then no more input data should be provided before the deflateParams() call. + If this is done, the old level and strategy will be applied to the data + compressed before deflateParams(), and the new level and strategy will be + applied to the the data compressed after deflateParams(). + + deflateParams returns Z_OK on success, Z_STREAM_ERROR if the source stream + state was inconsistent or if a parameter was invalid, or Z_BUF_ERROR if + there was not enough output space to complete the compression of the + available input data before a change in the strategy or approach. Note that + in the case of a Z_BUF_ERROR, the parameters are not changed. A return + value of Z_BUF_ERROR is not fatal, in which case deflateParams() can be + retried with more output space. +*/ + +int deflateTune(z_streamp strm, int good_length, int max_lazy, int nice_length, + int max_chain); +/* + Fine tune deflate's internal compression parameters. This should only be + used by someone who understands the algorithm used by zlib's deflate for + searching for the best matching string, and even then only by the most + fanatic optimizer trying to squeeze out the last compressed bit for their + specific input data. Read the deflate.c source code for the meaning of the + max_lazy, good_length, nice_length, and max_chain parameters. + + deflateTune() can be called after deflateInit() or deflateInit2(), and + returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. + */ + +size_t deflateBound(z_streamp strm, size_t sourceLen); +/* + deflateBound() returns an upper bound on the compressed size after + deflation of sourceLen bytes. It must be called after deflateInit() or + deflateInit2(), and after deflateSetHeader(), if used. This would be used + to allocate an output buffer for deflation in a single pass, and so would be + called before deflate(). If that first deflate() call is provided the + sourceLen input bytes, an output buffer allocated to the size returned by + deflateBound(), and the flush value Z_FINISH, then deflate() is guaranteed + to return Z_STREAM_END. Note that it is possible for the compressed size to + be larger than the value returned by deflateBound() if flush options other + than Z_FINISH or Z_NO_FLUSH are used. +*/ + +int deflatePending(z_streamp strm, uint* pending, int* bits); +/* + deflatePending() returns the number of bytes and bits of output that have + been generated, but not yet provided in the available output. The bytes not + provided would be due to the available output space having being consumed. + The number of bits of output not provided are between 0 and 7, where they + await more bits to join them in order to fill out a full byte. If pending + or bits are Z_NULL, then those values are not set. + + deflatePending returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. + */ + +int deflatePrime(z_streamp strm, int bits, int value); +/* + deflatePrime() inserts bits in the deflate output stream. The intent + is that this function is used to start off the deflate output with the bits + leftover from a previous deflate stream when appending to it. As such, this + function can only be used for raw deflate, and must be used before the first + deflate() call after a deflateInit2() or deflateReset(). bits must be less + than or equal to 16, and that many of the least significant bits of value + will be inserted in the output. + + deflatePrime returns Z_OK if success, Z_BUF_ERROR if there was not enough + room in the internal buffer to insert the bits, or Z_STREAM_ERROR if the + source stream state was inconsistent. +*/ + +int deflateSetHeader(z_streamp strm, gz_headerp head); +/* + deflateSetHeader() provides gzip header information for when a gzip + stream is requested by deflateInit2(). deflateSetHeader() may be called + after deflateInit2() or deflateReset() and before the first call of + deflate(). The text, time, os, extra field, name, and comment information + in the provided gz_header structure are written to the gzip header (xflag is + ignored -- the extra flags are set according to the compression level). The + caller must assure that, if not Z_NULL, name and comment are terminated with + a zero byte, and that if extra is not Z_NULL, that extra_len bytes are + available there. If hcrc is true, a gzip header crc is included. Note that + the current versions of the command-line version of gzip (up through version + 1.3.x) do not support header crc's, and will report that it is a "multi-part + gzip file" and give up. + + If deflateSetHeader is not used, the default gzip header has text false, + the time set to zero, and os set to 255, with no extra, name, or comment + fields. The gzip header is returned to the default state by deflateReset(). + + deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +int inflateInit2(z_streamp strm, int windowBits) +{ + return inflateInit2_(strm, windowBits, ZLIB_VERSION.ptr, z_stream.sizeof); +} +/* + This is another version of inflateInit with an extra parameter. The + fields next_in, avail_in, zalloc, zfree and opaque must be initialized + before by the caller. + + The windowBits parameter is the base two logarithm of the maximum window + size (the size of the history buffer). It should be in the range 8 .. 15 for + this version of the library. The default value is 15 if inflateInit is used + instead. windowBits must be greater than or equal to the windowBits value + provided to deflateInit2() while compressing, or it must be equal to 15 if + deflateInit2() was not used. If a compressed stream with a larger window + size is given as input, inflate() will return with the error code + Z_DATA_ERROR instead of trying to allocate a larger window. + + windowBits can also be zero to request that inflate use the window size in + the zlib header of the compressed stream. + + windowBits can also be -8..-15 for raw inflate. In this case, -windowBits + determines the window size. inflate() will then process raw deflate data, + not looking for a zlib or gzip header, not generating a check value, and not + looking for any check values for comparison at the end of the stream. This + is for use with other formats that use the deflate compressed data format + such as zip. Those formats provide their own check values. If a custom + format is developed using the raw deflate format for compressed data, it is + recommended that a check value such as an Adler-32 or a CRC-32 be applied to + the uncompressed data as is done in the zlib, gzip, and zip formats. For + most applications, the zlib format should be used as is. Note that comments + above on the use in deflateInit2() applies to the magnitude of windowBits. + + windowBits can also be greater than 15 for optional gzip decoding. Add + 32 to windowBits to enable zlib and gzip decoding with automatic header + detection, or add 16 to decode only the gzip format (the zlib format will + return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a + CRC-32 instead of an Adler-32. Unlike the gunzip utility and gzread() (see + below), inflate() will not automatically decode concatenated gzip streams. + inflate() will return Z_STREAM_END at the end of the gzip stream. The state + would need to be reset to continue decoding a subsequent gzip stream. + + inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_VERSION_ERROR if the zlib library version is incompatible with the + version assumed by the caller, or Z_STREAM_ERROR if the parameters are + invalid, such as a null pointer to the structure. msg is set to null if + there is no error message. inflateInit2 does not perform any decompression + apart from possibly reading the zlib header if present: actual decompression + will be done by inflate(). (So next_in and avail_in may be modified, but + next_out and avail_out are unused and unchanged.) The current implementation + of inflateInit2() does not process any header information -- that is + deferred until inflate() is called. +*/ + +int inflateSetDictionary(z_streamp strm, const(ubyte)* dictionary, uint dictLength); +/* + Initializes the decompression dictionary from the given uncompressed byte + sequence. This function must be called immediately after a call of inflate, + if that call returned Z_NEED_DICT. The dictionary chosen by the compressor + can be determined from the Adler-32 value returned by that call of inflate. + The compressor and decompressor must use exactly the same dictionary (see + deflateSetDictionary). For raw inflate, this function can be called at any + time to set the dictionary. If the provided dictionary is smaller than the + window and there is already data in the window, then the provided dictionary + will amend what's there. The application must insure that the dictionary + that was used for compression is provided. + + inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a + parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is + inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the + expected one (incorrect Adler-32 value). inflateSetDictionary does not + perform any decompression: this will be done by subsequent calls of + inflate(). +*/ + +int inflateGetDictionary(z_streamp strm, ubyte* dictionary, uint* dictLength); +/* + Returns the sliding dictionary being maintained by inflate. dictLength is + set to the number of bytes in the dictionary, and that many bytes are copied + to dictionary. dictionary must have enough space, where 32768 bytes is + always enough. If inflateGetDictionary() is called with dictionary equal to + Z_NULL, then only the dictionary length is returned, and nothing is copied. + Similary, if dictLength is Z_NULL, then it is not set. + + inflateGetDictionary returns Z_OK on success, or Z_STREAM_ERROR if the + stream state is inconsistent. +*/ + +int inflateSync(z_streamp strm); +/* + Skips invalid compressed data until a possible full flush point (see above + for the description of deflate with Z_FULL_FLUSH) can be found, or until all + available input is skipped. No output is provided. + + inflateSync searches for a 00 00 FF FF pattern in the compressed data. + All full flush points have this pattern, but not all occurrences of this + pattern are full flush points. + + inflateSync returns Z_OK if a possible full flush point has been found, + Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no flush point + has been found, or Z_STREAM_ERROR if the stream structure was inconsistent. + In the success case, the application may save the current current value of + total_in which indicates where valid compressed data was found. In the + error case, the application may repeatedly call inflateSync, providing more + input each time, until success or end of the input data. +*/ + +int inflateCopy(z_streamp dest, z_streamp source); +/* + Sets the destination stream as a complete copy of the source stream. + + This function can be useful when randomly accessing a large stream. The + first pass through the stream can periodically record the inflate state, + allowing restarting inflate at those points when randomly accessing the + stream. + + inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_STREAM_ERROR if the source stream state was inconsistent + (such as zalloc being Z_NULL). msg is left unchanged in both source and + destination. +*/ + +int inflateReset(z_streamp strm); +/* + This function is equivalent to inflateEnd followed by inflateInit, + but does not free and reallocate the internal decompression state. The + stream will keep attributes that may have been set by inflateInit2. + + inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL). +*/ + +int inflateReset2(z_streamp strm, int windowBits); +/* + This function is the same as inflateReset, but it also permits changing + the wrap and window size requests. The windowBits parameter is interpreted + the same as it is for inflateInit2. If the window size is changed, then the + memory allocated for the window is freed, and the window will be reallocated + by inflate() if needed. + + inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent (such as zalloc or state being Z_NULL), or if + the windowBits parameter is invalid. +*/ + +int inflatePrime(z_streamp strm, int bits, int value); +/* + This function inserts bits in the inflate input stream. The intent is + that this function is used to start inflating at a bit position in the + middle of a byte. The provided bits will be used before any bytes are used + from next_in. This function should only be used with raw inflate, and + should be used before the first inflate() call after inflateInit2() or + inflateReset(). bits must be less than or equal to 16, and that many of the + least significant bits of value will be inserted in the input. + + If bits is negative, then the input stream bit buffer is emptied. Then + inflatePrime() can be called again to put bits in the buffer. This is used + to clear out bits leftover after feeding inflate a block description prior + to feeding inflate codes. + + inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + +c_long inflateMark(z_streamp strm); +/* + This function returns two values, one in the lower 16 bits of the return + value, and the other in the remaining upper bits, obtained by shifting the + return value down 16 bits. If the upper value is -1 and the lower value is + zero, then inflate() is currently decoding information outside of a block. + If the upper value is -1 and the lower value is non-zero, then inflate is in + the middle of a stored block, with the lower value equaling the number of + bytes from the input remaining to copy. If the upper value is not -1, then + it is the number of bits back from the current bit position in the input of + the code (literal or length/distance pair) currently being processed. In + that case the lower value is the number of bytes already emitted for that + code. + + A code is being processed if inflate is waiting for more input to complete + decoding of the code, or if it has completed decoding but is waiting for + more output space to write the literal or match data. + + inflateMark() is used to mark locations in the input data for random + access, which may be at bit positions, and to note those cases where the + output of a code may span boundaries of random access blocks. The current + location in the input stream can be determined from avail_in and data_type + as noted in the description for the Z_BLOCK flush parameter for inflate. + + inflateMark returns the value noted above, or -65536 if the provided + source stream state was inconsistent. +*/ + +int inflateGetHeader(z_streamp strm, gz_headerp head); +/* + inflateGetHeader() requests that gzip header information be stored in the + provided gz_header structure. inflateGetHeader() may be called after + inflateInit2() or inflateReset(), and before the first call of inflate(). + As inflate() processes the gzip stream, head->done is zero until the header + is completed, at which time head->done is set to one. If a zlib stream is + being decoded, then head->done is set to -1 to indicate that there will be + no gzip header information forthcoming. Note that Z_BLOCK or Z_TREES can be + used to force inflate() to return immediately after header processing is + complete and before any actual data is decompressed. + + The text, time, xflags, and os fields are filled in with the gzip header + contents. hcrc is set to true if there is a header CRC. (The header CRC + was valid if done is set to one.) If extra is not Z_NULL, then extra_max + contains the maximum number of bytes to write to extra. Once done is true, + extra_len contains the actual extra field length, and extra contains the + extra field, or that field truncated if extra_max is less than extra_len. + If name is not Z_NULL, then up to name_max characters are written there, + terminated with a zero unless the length is greater than name_max. If + comment is not Z_NULL, then up to comm_max characters are written there, + terminated with a zero unless the length is greater than comm_max. When any + of extra, name, or comment are not Z_NULL and the respective field is not + present in the header, then that field is set to Z_NULL to signal its + absence. This allows the use of deflateSetHeader() with the returned + structure to duplicate the header. However if those fields are set to + allocated memory, then the application will need to save those pointers + elsewhere so that they can be eventually freed. + + If inflateGetHeader is not used, then the header information is simply + discarded. The header is always checked for validity, including the header + CRC if present. inflateReset() will reset the process to discard the header + information. The application would need to call inflateGetHeader() again to + retrieve the header from the next gzip stream. + + inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source + stream state was inconsistent. +*/ + + +int inflateBackInit(z_stream* strm, int windowBits, ubyte* window) +{ + return inflateBackInit_(strm, windowBits, window, ZLIB_VERSION.ptr, z_stream.sizeof); +} +/* + Initialize the internal stream state for decompression using inflateBack() + calls. The fields zalloc, zfree and opaque in strm must be initialized + before the call. If zalloc and zfree are Z_NULL, then the default library- + derived memory allocation routines are used. windowBits is the base two + logarithm of the window size, in the range 8 .. 15. window is a caller + supplied buffer of that size. Except for special applications where it is + assured that deflate was used with small window sizes, windowBits must be 15 + and a 32K byte window must be supplied to be able to decompress general + deflate streams. + + See inflateBack() for the usage of these routines. + + inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of + the parameters are invalid, Z_MEM_ERROR if the internal state could not be + allocated, or Z_VERSION_ERROR if the version of the library does not match + the version of the header file. +*/ + +alias in_func = uint function(void*, ubyte**); +alias out_func = int function(void*, ubyte*, uint); + +int inflateBack(z_stream* strm, + in_func f_in, + void* in_desc, + out_func f_out, + void* out_desc); +/* + inflateBack() does a raw inflate with a single call using a call-back + interface for input and output. This is potentially more efficient than + inflate() for file i/o applications, in that it avoids copying between the + output and the sliding window by simply making the window itself the output + buffer. inflate() can be faster on modern CPUs when used with large + buffers. inflateBack() trusts the application to not change the output + buffer passed by the output function, at least until inflateBack() returns. + + inflateBackInit() must be called first to allocate the internal state + and to initialize the state with the user-provided window buffer. + inflateBack() may then be used multiple times to inflate a complete, raw + deflate stream with each call. inflateBackEnd() is then called to free the + allocated state. + + A raw deflate stream is one with no zlib or gzip header or trailer. + This routine would normally be used in a utility that reads zip or gzip + files and writes out uncompressed files. The utility would decode the + header and process the trailer on its own, hence this routine expects only + the raw deflate stream to decompress. This is different from the default + behavior of inflate(), which expects a zlib header and trailer around the + deflate stream. + + inflateBack() uses two subroutines supplied by the caller that are then + called by inflateBack() for input and output. inflateBack() calls those + routines until it reads a complete deflate stream and writes out all of the + uncompressed data, or until it encounters an error. The function's + parameters and return types are defined above in the in_func and out_func + typedefs. inflateBack() will call in(in_desc, &buf) which should return the + number of bytes of provided input, and a pointer to that input in buf. If + there is no input available, in() must return zero -- buf is ignored in that + case -- and inflateBack() will return a buffer error. inflateBack() will + call out(out_desc, buf, len) to write the uncompressed data buf[0 .. len-1]. + out() should return zero on success, or non-zero on failure. If out() + returns non-zero, inflateBack() will return with an error. Neither in() nor + out() are permitted to change the contents of the window provided to + inflateBackInit(), which is also the buffer that out() uses to write from. + The length written by out() will be at most the window size. Any non-zero + amount of input may be provided by in(). + + For convenience, inflateBack() can be provided input on the first call by + setting strm->next_in and strm->avail_in. If that input is exhausted, then + in() will be called. Therefore strm->next_in must be initialized before + calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called + immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in + must also be initialized, and then if strm->avail_in is not zero, input will + initially be taken from strm->next_in[0 .. strm->avail_in - 1]. + + The in_desc and out_desc parameters of inflateBack() is passed as the + first parameter of in() and out() respectively when they are called. These + descriptors can be optionally used to pass any information that the caller- + supplied in() and out() functions need to do their job. + + On return, inflateBack() will set strm->next_in and strm->avail_in to + pass back any unused input that was provided by the last in() call. The + return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR + if in() or out() returned an error, Z_DATA_ERROR if there was a format error + in the deflate stream (in which case strm->msg is set to indicate the nature + of the error), or Z_STREAM_ERROR if the stream was not properly initialized. + In the case of Z_BUF_ERROR, an input or output error can be distinguished + using strm->next_in which will be Z_NULL only if in() returned an error. If + strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning + non-zero. (in() will always be called before out(), so strm->next_in is + assured to be defined if out() returns non-zero.) Note that inflateBack() + cannot return Z_OK. +*/ + +int inflateBackEnd(z_stream* strm); +/* + All memory allocated by inflateBackInit() is freed. + + inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream + state was inconsistent. +*/ + +uint zlibCompileFlags(); +/* Return flags indicating compile-time options. + + Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: + 1.0: size of uInt + 3.2: size of uLong + 5.4: size of voidpf (pointer) + 7.6: size of z_off_t + + Compiler, assembler, and debug options: + 8: ZLIB_DEBUG + 9: ASMV or ASMINF -- use ASM code + 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention + 11: 0 (reserved) + + One-time table building (smaller code, but not thread-safe if true): + 12: BUILDFIXED -- build static block decoding tables when needed + 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed + 14,15: 0 (reserved) + + Library content (indicates missing functionality): + 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking + deflate code when not needed) + 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect + and decode gzip streams (to avoid linking crc code) + 18-19: 0 (reserved) + + Operation variations (changes in library functionality): + 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate + 21: FASTEST -- deflate algorithm with only one, lowest compression level + 22,23: 0 (reserved) + + The sprintf variant used by gzprintf (zero is best): + 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format + 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! + 26: 0 = returns value, 1 = void -- 1 means inferred string length returned + + Remainder: + 27-31: 0 (reserved) + */ + + /* utility functions */ + +/* + The following utility functions are implemented on top of the basic + stream-oriented functions. To simplify the interface, some default options + are assumed (compression level and memory usage, standard memory allocation + functions). The source code of these utility functions can be modified if + you need special options. +*/ + +int compress(ubyte* dest, + size_t* destLen, + const(ubyte)* source, + size_t sourceLen); +/* + Compresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total size + of the destination buffer, which must be at least the value returned by + compressBound(sourceLen). Upon exit, destLen is the actual size of the + compressed data. compress() is equivalent to compress2() with a level + parameter of Z_DEFAULT_COMPRESSION. + + compress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer. +*/ + +int compress2(ubyte* dest, + size_t* destLen, + const(ubyte)* source, + size_t sourceLen, + int level); +/* + Compresses the source buffer into the destination buffer. The level + parameter has the same meaning as in deflateInit. sourceLen is the byte + length of the source buffer. Upon entry, destLen is the total size of the + destination buffer, which must be at least the value returned by + compressBound(sourceLen). Upon exit, destLen is the actual size of the + compressed data. + + compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough + memory, Z_BUF_ERROR if there was not enough room in the output buffer, + Z_STREAM_ERROR if the level parameter is invalid. +*/ + +size_t compressBound(size_t sourceLen); +/* + compressBound() returns an upper bound on the compressed size after + compress() or compress2() on sourceLen bytes. It would be used before a + compress() or compress2() call to allocate the destination buffer. +*/ + +int uncompress(ubyte* dest, + size_t* destLen, + const(ubyte)* source, + size_t sourceLen); +/* + Decompresses the source buffer into the destination buffer. sourceLen is + the byte length of the source buffer. Upon entry, destLen is the total size + of the destination buffer, which must be large enough to hold the entire + uncompressed data. (The size of the uncompressed data must have been saved + previously by the compressor and transmitted to the decompressor by some + mechanism outside the scope of this compression library.) Upon exit, destLen + is the actual size of the uncompressed data. + + uncompress returns Z_OK if success, Z_MEM_ERROR if there was not + enough memory, Z_BUF_ERROR if there was not enough room in the output + buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. In + the case where there is not enough room, uncompress() will fill the output + buffer with the uncompressed data up to that point. +*/ + +int uncompress2(ubyte* dest, + size_t* destLen, + const(ubyte)* source, + size_t* sourceLen); +/* + Same as uncompress, except that sourceLen is a pointer, where the + length of the source is *sourceLen. On return, *sourceLen is the number of + source bytes consumed. +*/ + + /* gzip file access functions */ + +/* + This library supports reading and writing files in gzip (.gz) format with + an interface similar to that of stdio, using the functions that start with + "gz". The gzip format is different from the zlib format. gzip is a gzip + wrapper, documented in RFC 1952, wrapped around a deflate stream. +*/ + +alias gzFile = void*; +alias z_off_t = int; // file offset +alias z_size_t = size_t; + +gzFile gzopen(const(char)* path, const(char)* mode); +/* + Opens a gzip (.gz) file for reading or writing. The mode parameter is as + in fopen ("rb" or "wb") but can also include a compression level ("wb9") or + a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only + compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F' + for fixed code compression as in "wb9F". (See the description of + deflateInit2 for more information about the strategy parameter.) 'T' will + request transparent writing or appending with no compression and not using + the gzip format. + + "a" can be used instead of "w" to request that the gzip stream that will + be written be appended to the file. "+" will result in an error, since + reading and writing to the same gzip file is not supported. The addition of + "x" when writing will create the file exclusively, which fails if the file + already exists. On systems that support it, the addition of "e" when + reading or writing will set the flag to close the file on an execve() call. + + These functions, as well as gzip, will read and decode a sequence of gzip + streams in a file. The append function of gzopen() can be used to create + such a file. (Also see gzflush() for another way to do this.) When + appending, gzopen does not test whether the file begins with a gzip stream, + nor does it look for the end of the gzip streams to begin appending. gzopen + will simply append a gzip stream to the existing file. + + gzopen can be used to read a file which is not in gzip format; in this + case gzread will directly read from the file without decompression. When + reading, this will be detected automatically by looking for the magic two- + byte gzip header. + + gzopen returns NULL if the file could not be opened, if there was + insufficient memory to allocate the gzFile state, or if an invalid mode was + specified (an 'r', 'w', or 'a' was not provided, or '+' was provided). + errno can be checked to determine if the reason gzopen failed was that the + file could not be opened. +*/ + +gzFile gzdopen(int fd, const(char)* mode); +/* + gzdopen associates a gzFile with the file descriptor fd. File descriptors + are obtained from calls like open, dup, creat, pipe or fileno (if the file + has been previously opened with fopen). The mode parameter is as in gzopen. + + The next call of gzclose on the returned gzFile will also close the file + descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor + fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd, + mode);. The duplicated descriptor should be saved to avoid a leak, since + gzdopen does not close fd if it fails. If you are using fileno() to get the + file descriptor from a FILE *, then you will have to use dup() to avoid + double-close()ing the file descriptor. Both gzclose() and fclose() will + close the associated file descriptor, so they need to have different file + descriptors. + + gzdopen returns NULL if there was insufficient memory to allocate the + gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not + provided, or '+' was provided), or if fd is -1. The file descriptor is not + used until the next gz* read, write, seek, or close operation, so gzdopen + will not detect if fd is invalid (unless fd is -1). +*/ + +int gzbuffer(gzFile file, uint size); +/* + Set the internal buffer size used by this library's functions. The + default buffer size is 8192 bytes. This function must be called after + gzopen() or gzdopen(), and before any other calls that read or write the + file. The buffer memory allocation is always deferred to the first read or + write. Three times that size in buffer space is allocated. A larger buffer + size of, for example, 64K or 128K bytes will noticeably increase the speed + of decompression (reading). + + The new buffer size also affects the maximum length for gzprintf(). + + gzbuffer() returns 0 on success, or -1 on failure, such as being called + too late. +*/ + +int gzsetparams(gzFile file, int level, int strategy); +/* + Dynamically update the compression level or strategy. See the description + of deflateInit2 for the meaning of these parameters. Previously provided + data is flushed before the parameter change. + + gzsetparams returns Z_OK if success, Z_STREAM_ERROR if the file was not + opened for writing, Z_ERRNO if there is an error writing the flushed data, + or Z_MEM_ERROR if there is a memory allocation error. +*/ + +int gzread(gzFile file, void* buf, uint len); +/* + Reads the given number of uncompressed bytes from the compressed file. If + the input file is not in gzip format, gzread copies the given number of + bytes into the buffer directly from the file. + + After reaching the end of a gzip stream in the input, gzread will continue + to read, looking for another gzip stream. Any number of gzip streams may be + concatenated in the input file, and will all be decompressed by gzread(). + If something other than a gzip stream is encountered after a gzip stream, + that remaining trailing garbage is ignored (and no error is returned). + + gzread can be used to read a gzip file that is being concurrently written. + Upon reaching the end of the input, gzread will return with the available + data. If the error code returned by gzerror is Z_OK or Z_BUF_ERROR, then + gzclearerr can be used to clear the end of file indicator in order to permit + gzread to be tried again. Z_OK indicates that a gzip stream was completed + on the last gzread. Z_BUF_ERROR indicates that the input file ended in the + middle of a gzip stream. Note that gzread does not return -1 in the event + of an incomplete gzip stream. This error is deferred until gzclose(), which + will return Z_BUF_ERROR if the last gzread ended in the middle of a gzip + stream. Alternatively, gzerror can be used before gzclose to detect this + case. + + gzread returns the number of uncompressed bytes actually read, less than + len for end of file, or -1 for error. If len is too large to fit in an int, + then nothing is read, -1 is returned, and the error state is set to + Z_STREAM_ERROR. +*/ + +z_size_t gzfread(void* buf, z_size_t size, z_size_t nitems, gzFile file); +/* + Read up to nitems items of size size from file to buf, otherwise operating + as gzread() does. This duplicates the interface of stdio's fread(), with + size_t request and return types. If the library defines size_t, then + z_size_t is identical to size_t. If not, then z_size_t is an unsigned + integer type that can contain a pointer. + + gzfread() returns the number of full items read of size size, or zero if + the end of the file was reached and a full item could not be read, or if + there was an error. gzerror() must be consulted if zero is returned in + order to determine if there was an error. If the multiplication of size and + nitems overflows, i.e. the product does not fit in a z_size_t, then nothing + is read, zero is returned, and the error state is set to Z_STREAM_ERROR. + + In the event that the end of file is reached and only a partial item is + available at the end, i.e. the remaining uncompressed data length is not a + multiple of size, then the final partial item is nevetheless read into buf + and the end-of-file flag is set. The length of the partial item read is not + provided, but could be inferred from the result of gztell(). This behavior + is the same as the behavior of fread() implementations in common libraries, + but it prevents the direct use of gzfread() to read a concurrently written + file, reseting and retrying on end-of-file, when size is not 1. +*/ + +int gzwrite(gzFile file, void* buf, uint len); +/* + Writes the given number of uncompressed bytes into the compressed file. + gzwrite returns the number of uncompressed bytes written or 0 in case of + error. +*/ + +z_size_t gzfwrite(void* buf, z_size_t size, z_size_t nitems, gzFile file); +/* + gzfwrite() writes nitems items of size size from buf to file, duplicating + the interface of stdio's fwrite(), with size_t request and return types. If + the library defines size_t, then z_size_t is identical to size_t. If not, + then z_size_t is an unsigned integer type that can contain a pointer. + + gzfwrite() returns the number of full items written of size size, or zero + if there was an error. If the multiplication of size and nitems overflows, + i.e. the product does not fit in a z_size_t, then nothing is written, zero + is returned, and the error state is set to Z_STREAM_ERROR. +*/ + +int gzprintf(gzFile file, const(char)* format, ...); +/* + Converts, formats, and writes the arguments to the compressed file under + control of the format string, as in fprintf. gzprintf returns the number of + uncompressed bytes actually written, or a negative zlib error code in case + of error. The number of uncompressed bytes written is limited to 8191, or + one less than the buffer size given to gzbuffer(). The caller should assure + that this limit is not exceeded. If it is exceeded, then gzprintf() will + return an error (0) with nothing written. In this case, there may also be a + buffer overflow with unpredictable consequences, which is possible only if + zlib was compiled with the insecure functions sprintf() or vsprintf() + because the secure snprintf() or vsnprintf() functions were not available. + This can be determined using zlibCompileFlags(). +*/ + +int gzputs(gzFile file, const(char)* s); +/* + Writes the given null-terminated string to the compressed file, excluding + the terminating null character. + + gzputs returns the number of characters written, or -1 in case of error. +*/ + +const(char)* gzgets(gzFile file, const(char)* buf, int len); +/* + Reads bytes from the compressed file until len-1 characters are read, or a + newline character is read and transferred to buf, or an end-of-file + condition is encountered. If any characters are read or if len == 1, the + string is terminated with a null character. If no characters are read due + to an end-of-file or len < 1, then the buffer is left untouched. + + gzgets returns buf which is a null-terminated string, or it returns NULL + for end-of-file or in case of error. If there was an error, the contents at + buf are indeterminate. +*/ + +int gzputc(gzFile file, int c); +/* + Writes c, converted to an unsigned char, into the compressed file. gzputc + returns the value that was written, or -1 in case of error. +*/ + +int gzgetc(gzFile file); +/* + Reads one byte from the compressed file. gzgetc returns this byte or -1 + in case of end of file or error. This is implemented as a macro for speed. + As such, it does not do all of the checking the other functions do. I.e. + it does not check to see if file is NULL, nor whether the structure file + points to has been clobbered or not. +*/ + +int gzungetc(int c, gzFile file); +/* + Push one character back onto the stream to be read as the first character + on the next read. At least one character of push-back is allowed. + gzungetc() returns the character pushed, or -1 on failure. gzungetc() will + fail if c is -1, and may fail if a character has been pushed but not read + yet. If gzungetc is used immediately after gzopen or gzdopen, at least the + output buffer size of pushed characters is allowed. (See gzbuffer above.) + The pushed character will be discarded if the stream is repositioned with + gzseek() or gzrewind(). +*/ + +int gzflush(gzFile file, int flush); +/* + Flushes all pending output into the compressed file. The parameter flush + is as in the deflate() function. The return value is the zlib error number + (see function gzerror below). gzflush is only permitted when writing. + + If the flush parameter is Z_FINISH, the remaining data is written and the + gzip stream is completed in the output. If gzwrite() is called again, a new + gzip stream will be started in the output. gzread() is able to read such + concatenated gzip streams. + + gzflush should be called only when strictly necessary because it will + degrade compression if called too often. +*/ + +z_off_t gzseek(gzFile file, z_off_t offset, int whence); +/* + Sets the starting position for the next gzread or gzwrite on the given + compressed file. The offset represents a number of bytes in the + uncompressed data stream. The whence parameter is defined as in lseek(2); + the value SEEK_END is not supported. + + If the file is opened for reading, this function is emulated but can be + extremely slow. If the file is opened for writing, only forward seeks are + supported; gzseek then compresses a sequence of zeroes up to the new + starting position. + + gzseek returns the resulting offset location as measured in bytes from + the beginning of the uncompressed stream, or -1 in case of error, in + particular if the file is opened for writing and the new starting position + would be before the current position. +*/ + +int gzrewind(gzFile file); +/* + Rewinds the given file. This function is supported only for reading. + + gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) +*/ + +z_off_t gztell(gzFile file); +/* + Returns the starting position for the next gzread or gzwrite on the given + compressed file. This position represents a number of bytes in the + uncompressed data stream, and is zero when starting, even if appending or + reading a gzip stream from the middle of a file using gzdopen(). + + gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) +*/ + +z_off_t gzoffset(gzFile file); +/* + Returns the current offset in the file being read or written. This offset + includes the count of bytes that precede the gzip stream, for example when + appending or when using gzdopen() for reading. When reading, the offset + does not include as yet unused buffered input. This information can be used + for a progress indicator. On error, gzoffset() returns -1. +*/ + +int gzeof(gzFile file); +/* + Returns true (1) if the end-of-file indicator has been set while reading, + false (0) otherwise. Note that the end-of-file indicator is set only if the + read tried to go past the end of the input, but came up short. Therefore, + just like feof(), gzeof() may return false even if there is no more data to + read, in the event that the last read request was for the exact number of + bytes remaining in the input file. This will happen if the input file size + is an exact multiple of the buffer size. + + If gzeof() returns true, then the read functions will return no more data, + unless the end-of-file indicator is reset by gzclearerr() and the input file + has grown since the previous end of file was detected. +*/ + +int gzdirect(gzFile file); +/* + Returns true (1) if file is being copied directly while reading, or false + (0) if file is a gzip stream being decompressed. + + If the input file is empty, gzdirect() will return true, since the input + does not contain a gzip stream. + + If gzdirect() is used immediately after gzopen() or gzdopen() it will + cause buffers to be allocated to allow reading the file to determine if it + is a gzip file. Therefore if gzbuffer() is used, it should be called before + gzdirect(). + + When writing, gzdirect() returns true (1) if transparent writing was + requested ("wT" for the gzopen() mode), or false (0) otherwise. (Note: + gzdirect() is not needed when writing. Transparent writing must be + explicitly requested, so the application already knows the answer. When + linking statically, using gzdirect() will include all of the zlib code for + gzip file reading and decompression, which may not be desired.) +*/ + +int gzclose(gzFile file); +/* + Flushes all pending output if necessary, closes the compressed file and + deallocates the (de)compression state. Note that once file is closed, you + cannot call gzerror with file, since its structures have been deallocated. + gzclose must not be called more than once on the same file, just as free + must not be called more than once on the same allocation. + + gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a + file operation error, Z_MEM_ERROR if out of memory, Z_BUF_ERROR if the + last read ended in the middle of a gzip stream, or Z_OK on success. +*/ + +int gzclose_r(gzFile file); +int gzclose_w(gzFile file); +/* + Same as gzclose(), but gzclose_r() is only for use when reading, and + gzclose_w() is only for use when writing or appending. The advantage to + using these instead of gzclose() is that they avoid linking in zlib + compression or decompression code that is not used when only reading or only + writing respectively. If gzclose() is used, then both compression and + decompression code will be included the application when linking to a static + zlib library. +*/ + +const(char)* gzerror(gzFile file, int* errnum); +/* + Returns the error message for the last error which occurred on the given + compressed file. errnum is set to zlib error number. If an error occurred + in the file system and not in the compression library, errnum is set to + Z_ERRNO and the application may consult errno to get the exact error code. + + The application must not modify the returned string. Future calls to + this function may invalidate the previously returned string. If file is + closed, then the string previously returned by gzerror will no longer be + available. + + gzerror() should be used to distinguish errors from end-of-file for those + functions above that do not distinguish those cases in their return values. +*/ + +void gzclearerr(gzFile file); +/* + Clears the error and end-of-file flags for file. This is analogous to the + clearerr() function in stdio. This is useful for continuing to read a gzip + file that is being written concurrently. +*/ + + /* checksum functions */ + +/* + These functions are not related to compression but are exported + anyway because they might be useful in applications using the compression + library. +*/ + +uint adler32(uint adler, const(ubyte)* buf, uint len); +/* + Update a running Adler-32 checksum with the bytes buf[0 .. len-1] and + return the updated checksum. If buf is Z_NULL, this function returns the + required initial value for the checksum. + + An Adler-32 checksum is almost as reliable as a CRC-32 but can be computed + much faster. + + Usage example: + + uLong adler = adler32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) + adler = adler32(adler, buffer, length); + + if (adler != original_adler) error(); +*/ + +uint adler32_z (uint adler, const(ubyte)* buf, z_size_t len); +/* + Same as adler32(), but with a size_t length. +*/ + +uint adler32_combine(uint adler1, uint adler2, z_off_t len2); +/* + Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 + and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for + each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of + seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. Note + that the z_off_t type (like off_t) is a signed integer. If len2 is + negative, the result has no meaning or utility. +*/ + +uint crc32(uint crc, const(ubyte)* buf, uint len); +/* + Update a running CRC-32 with the bytes buf[0 .. len-1] and return the + updated CRC-32. If buf is Z_NULL, this function returns the required + initial value for the crc. Pre- and post-conditioning (one's complement) is + performed within this function so it shouldn't be done by the application. + + Usage example: + + uLong crc = crc32(0L, Z_NULL, 0); + + while (read_buffer(buffer, length) != EOF) + crc = crc32(crc, buffer, length); + + if (crc != original_crc) error(); +*/ + +uint crc32_z(uint adler, const(ubyte)* buf, z_size_t len); +/* + Same as crc32(), but with a size_t length. +*/ + +uint crc32_combine(uint crc1, uint crc2, z_off_t len2); + +/* + Combine two CRC-32 check values into one. For two sequences of bytes, + seq1 and seq2 with lengths len1 and len2, CRC-32 check values were + calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 + check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and + len2. +*/ + + + /* various hacks, don't look :) */ + +/* deflateInit and inflateInit are macros to allow checking the zlib version + * and the compiler's view of z_stream: + */ +int deflateInit_(z_streamp strm, + int level, + const(char)* versionx, + int stream_size); + +int inflateInit_(z_streamp strm, + const(char)* versionx, + int stream_size); + +int deflateInit2_(z_streamp strm, + int level, + int method, + int windowBits, + int memLevel, + int strategy, + const(char)* versionx, + int stream_size); + +int inflateBackInit_(z_stream* strm, + int windowBits, + ubyte* window, + const(char)* z_version, + int stream_size); + +int inflateInit2_(z_streamp strm, + int windowBits, + const(char)* versionx, + int stream_size); + +const(char)* zError(int err); +int inflateSyncPoint(z_streamp z); +const(uint)* get_crc_table(); |