Global Zig Reference Documentation
Global
Current Version: 11.6.1
Chilkat.Global
Call
Configure process-wide defaults such as ANSI code page handling, DNS
caching behavior, IPv6 preference, and NTLM version selection.
Enable additional diagnostic behavior such as verbose TLS logging and
thread-pool logging when troubleshooting difficult runtime issues.
Control the limits and behavior of Chilkat's internal thread pool used by
asynchronous task-based methods.
Adjust DNS and IP-version preferences that can affect how Chilkat classes
resolve names and establish network connections.
Set specialized process-wide options for interoperability scenarios, such
as special PKCS#7 encoding behavior.
For an extended overview, see
Global Class Overview.
Unlock Chilkat and configure library-wide defaults, diagnostics, and async behavior.
Chilkat.Global is the Chilkat class for library-wide
initialization, licensing, default behavior, diagnostics, and thread-pool
control. Its most important method is UnlockBundle, which should
be called once at application startup before using other Chilkat classes. It
also provides settings for DNS caching, ANSI code page behavior, NTLM
version, IPv6 preference, verbose TLS logging, async task execution,
thread-pool limits, thread-pool logging, and special PKCS#7 encoding
behavior.
Library unlocking
UnlockBundle once during application startup to unlock
Chilkat components for use throughout the process.
Global defaults
Diagnostics and logging
Async thread pool
Network-related behavior
Compatibility options
Chilkat.Global object at application startup, call
UnlockBundle once, then set any process-wide defaults before
creating and using other Chilkat objects. Treat these settings as
application-wide configuration, not per-object state.
Object Creation
// Add the package once:
// zig fetch --save https://chilkatdownload.com/11.6.1/chilkat-zig-11.6.1.tar.gz
// and in build.zig:
// const chilkat = b.dependency("chilkat", .{ .target = target, .optimize = optimize });
// exe.root_module.addImport("chilkat", chilkat.module("chilkat"));
const chilkat = @import("chilkat");
// Once per process, before any other Chilkat call:
try chilkat.unlockBundle("Anything for 30-day trial");
const global = try chilkat.Global.init();
defer global.deinit();Creates the underlying native Chilkat object. Global is a one-pointer struct passed by value; copying it copies the handle (two names for one object). Returns error.OutOfMemory if the library could not allocate the object. Use an object from one thread at a time; it may be handed from one thread to another.
Releases the native object. Call it exactly once per object (usually with defer); the handle is invalid afterwards. Objects returned by methods are owned by the caller too and are released the same way.
Wraps a handle obtained from the C API (chilkat.c.CkGlobal), taking ownership of it. The struct's handle field goes the other way, for anything the Zig API does not cover.
Errors and memory
Methods that can fail return an error union: a method whose only outcome is success or failure returns Error!void; a method producing a string returns (Error || Allocator.Error)![:0]u8; a method producing an object returns Error!T. chilkat.Error is error{ChilkatFailed}; the reason for a failure is in getLastErrorText, and the object remains usable. Properties never fail, and methods that answer a question (hasMember, isUnlocked, ...) return a plain bool.
String arguments are [:0]const u8 (UTF-8; string literals can be passed as is). String results are copies allocated with the allocator argument and owned by the caller, so they stay valid across later calls on the same object.
const text = global.someMethod(allocator, ...) catch |err| {
const why = try global.getLastErrorText(allocator);
defer allocator.free(why);
std.debug.print("{s}\n", .{why});
return err;
};
defer allocator.free(text);
Properties
AnsiCodePage
pub fn getAnsiCodePage(self: Global) i32
pub fn setAnsiCodePage(self: Global, value: i32) void
The default ANSI code page is determined at runtime based on the computer where the application happens to be running. For example, the ANSI code page for an application running on a Japanese computer is likely to be Shift_JIS (code page 932), whereas on a US-English computer it would be iso-8859-1 (or Windows-1252 which is essentially a superset of iso-8859-1).
If there is a desire for the Chilkat library to use a specific ANSI code page regardless of locale, then this property should be set to the desired code page. The default value of this property is the ANSI code page of the local computer.
topAutoQBDecode
pub fn getAutoQBDecode(self: Global) bool
pub fn setAutoQBDecode(self: Global, value: bool) void
If set to true, then Q or B encoded strings can be passed in any string argument to any Chilkat method, and Chilkat will automatically decode the string before using it. This is meant to be a convenient way to use non-usascii literal strings in your source code. See the links below for an example and for a discussion about non-usascii literal strings.
DebugLogFilePath
pub fn getDebugLogFilePath(self: Global, allocator: Allocator) Allocator.Error![:0]u8
pub fn setDebugLogFilePath(self: Global, value: [:0]const u8) void
If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.
Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.
Possible causes of hangs include:
- A timeout property set to 0, indicating an infinite timeout.
- A hang occurring within an event callback in the application code.
- An internal bug in the Chilkat code causing the hang.
DefaultNtlmVersion
pub fn getDefaultNtlmVersion(self: Global) i32
pub fn setDefaultNtlmVersion(self: Global, value: i32) void
Selects the default NTLM protocol version to use for NTLM authentication for HTTP, POP3, IMAP, SMTP, and HTTP proxies. The default value is 2. This property may optionally be set to 1.
DnsTimeToLive
pub fn getDnsTimeToLive(self: Global) i32
pub fn setDnsTimeToLive(self: Global, value: i32) void
If DNS caching is enabled, this is the time-to-live (in seconds) for a cached DNS lookup. A DNS lookup result older than this expiration time is discarded, and causes a new DNS lookup to occur. A value of 0 indicates an infinite time-to-live. The default value of this property is 0.
topEnableDnsCaching
pub fn getEnableDnsCaching(self: Global) bool
pub fn setEnableDnsCaching(self: Global, value: bool) void
Controls whether DNS domain lookups (to resolve to IP addresses) are cached in memory. The default value is false, meaning that DNS caching is disabled.
LastErrorHtml
pub fn getLastErrorHtml(self: Global, allocator: Allocator) Allocator.Error![:0]u8
Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastErrorText
pub fn getLastErrorText(self: Global, allocator: Allocator) Allocator.Error![:0]u8
Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
LastErrorXml
pub fn getLastErrorXml(self: Global, allocator: Allocator) Allocator.Error![:0]u8
Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastMethodSuccess
pub fn getLastMethodSuccess(self: Global) bool
pub fn setLastMethodSuccess(self: Global, value: bool) void
Indicates the success or failure of the most recent method call: true means success, false means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.
MaxThreads
pub fn getMaxThreads(self: Global) i32
pub fn setMaxThreads(self: Global, value: i32) void
The maximum number of thread pool threads. The default value is 100. The maximum value is 500. Note: Asynchronous worker threads are created on as needed up to the maximum.
topPreferIpv6
pub fn getPreferIpv6(self: Global) bool
pub fn setPreferIpv6(self: Global, value: bool) void
If true, then use IPv6 over IPv4 when both are supported for a particular domain. The default value of this property is false, which will choose IPv4 over IPv6.
Note: Setting this property has the effect of also setting the default value of the PreferIpv6 property for other classes.
topThreadPoolLogPath
pub fn getThreadPoolLogPath(self: Global, allocator: Allocator) Allocator.Error![:0]u8
pub fn setThreadPoolLogPath(self: Global, value: [:0]const u8) void
If set, indicates the path of a log file to be used by the thread pool thread and each of the pool worker threads for logging async activity. Chilkat always appends to the log file. If the log file already exists, then new information will be appended.
topUncommonOptions
pub fn getUncommonOptions(self: Global, allocator: Allocator) Allocator.Error![:0]u8
pub fn setUncommonOptions(self: Global, value: [:0]const u8) void
This is a catch-all property to be used for uncommon needs. This property defaults to the empty string, and should typically remain empty.
topUnlockStatus
pub fn getUnlockStatus(self: Global) i32
Indicates the unlocked status for the last call to UnlockBundle. The possible values are:
- Not unlocked. (Still in locked state.)
- Unlocked with in fully-functional trial mode.
- Unlocked using a valid purchased unlock code.
Note: If UnlockBundle is called with a purchased unlock code, the UnlockStatus is correctly set to the value 2. This value is intentionally sticky. If a subsequent and redundant call to UnlockBundle happens, it is effectively a No-Op because the library is already unlocked. The UnlockStatus will not change.
If however, if the 1st call resulted in UnlockStatus = 1, and THEN the unlock method is called again with a purchased unlock code, the UnlockStatus should change from 1 to 2.
topUsePkcsConstructedEncoding
pub fn getUsePkcsConstructedEncoding(self: Global) bool
pub fn setUsePkcsConstructedEncoding(self: Global, value: bool) void
This property should typically be left at the default value of false. If set to true, then Chilkat will use a constructed ASN.1 encoding for PCKS7 data. (This is an internal implementation option that normally does not matter, and should not matter. Some PKCS7 receiving systems might be picky, and this option can be used to satisfy this requirement.)
VerboseLogging
pub fn getVerboseLogging(self: Global) bool
pub fn setVerboseLogging(self: Global, value: bool) void
If set to true, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is false. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.
VerboseTls
pub fn getVerboseTls(self: Global) bool
pub fn setVerboseTls(self: Global, value: bool) void
If set to true, then causes extremely verbose logging (in LastErrorText) all TLS connections in any Chilkat class. This property should only be used for troubleshooting TLS problems. The default value is false.
Note: This property only has effect on Chilkat objects not yet created. Set the property first, then instantiate the Chilkat object.
topVersion
pub fn getVersion(self: Global, allocator: Allocator) Allocator.Error![:0]u8
Methods
DnsClearCache
This function clears the Chilkat in-memory DNS cache, which stores hostname-to-IP address mappings to avoid repeated DNS lookups.
Note:
- The DNS cache is shared across all Chilkat objects, so clearing it will impact all such objects.
- Chilkat's DNS caching respects the TTL (time to live) of DNS records. If the TTL has expired since the initial lookup, Chilkat will perform a new DNS query and update the cache with the latest IP address.
Returns error.ChilkatFailed on failure; getLastErrorText explains why.
FinalizeThreadPool
Called to stop and finalize all threads in the thread pool, and causes the thread pool thread to exit.
The following behaviors exist in v9.5.0.64 and later:
- All remaining asynchronous tasks are automatically canceled.
- Restores the thread pool to it's pristine state where no background threads are running.
It is a good idea to call this method at the very end of a program, just before it exits. This is especially true for programs written in VBScript, VB6, FoxPro, and PowerBuilder.
Returns error.ChilkatFailed on failure; getLastErrorText explains why.
ThreadPoolLogLine
Logs a line to the thread pool log file.
Returns error.ChilkatFailed on failure; getLastErrorText explains why.
UnlockBundle
Unlocks the entire Chilkat API for all classes. This should be called once at the beginning of a program. Once unlocked, objects of any Chilkat class may be instantiated and used. To unlock in fully-functional 30-day trial mode, pass any string, such as Hello, in bundle_unlock_code. If a license is purchased, then replace the Hello with the purchased unlock code.
After calling UnlockBundle once, the instance of the Global object may be discarded/deleted (assuming the programming language requires explicit deletes). Multiple calls to UnlockBundle are harmless. If the Chilkat API is already unlocked, the duplicate calls to UnlockBundle are no-ops.
Important: Unlocking sets a flag in memory to indicate the unlocked status. There are no licensing files, and there is no communication with any Chilkat servers. This means your application, script, etc. must call UnlockBundle once at the start each time it runs. The good thing is that your application can run on any computer -- there are no licensing files to worry about. Also: If an application forgets to call UnlockBundle, Chilkat will automatically unlock in trial mode, and this will eventually fail when the trial runs out. If you purchased a license, it is very important to make sure you call UnlockBundle with the purchased unlock code.
Returns error.ChilkatFailed on failure; getLastErrorText explains why.