Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions Sources/PartoutCore/OpenAPI/Codegen/PartoutErrorCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,28 @@ public enum PartoutErrorCode: String, Sendable, Codable, CaseIterable {
/// Keychain item not found.
case keychainItemNotFound = "keychainItemNotFound"
/// Compression settings mismatch.
case openVPNCompressionMismatch = "OpenVPN.compressionMismatch"
case passphraseRequired = "passphraseRequired"
/// Connection failure.
case openVPNConnectionFailure = "OpenVPN.connectionFailure"
case openVPNCompressionMismatch = "OpenVPN.compressionMismatch"
/// No routing configuration.
case openVPNNoRouting = "OpenVPN.noRouting"
case openVPNConnectionFailure = "OpenVPN.connectionFailure"
/// One-time password is required.
case openVPNOTPRequired = "OpenVPN.otpRequired"
case openVPNNoRouting = "OpenVPN.noRouting"
/// Passphrase is required.
case openVPNPassphraseRequired = "OpenVPN.passphraseRequired"
case openVPNOTPRequired = "OpenVPN.otpRequired"
/// Authentication can be retried.
case openVPNRecoverableAuthentication = "OpenVPN.recoverableAuthentication"
case openVPNPassphraseRequired = "OpenVPN.passphraseRequired"
/// Server requested shutdown.
case openVPNServerShutdown = "OpenVPN.serverShutdown"
case openVPNRecoverableAuthentication = "OpenVPN.recoverableAuthentication"
/// TLS failure.
case openVPNTLSFailure = "OpenVPN.tlsFailure"
case openVPNServerShutdown = "OpenVPN.serverShutdown"
/// Algorithm is unsupported.
case openVPNUnsupportedAlgorithm = "OpenVPN.unsupportedAlgorithm"
case openVPNTLSFailure = "OpenVPN.tlsFailure"
/// Compression setting is unsupported.
case openVPNUnsupportedCompression = "OpenVPN.unsupportedCompression"
case openVPNUnsupportedAlgorithm = "OpenVPN.unsupportedAlgorithm"
/// Option is unsupported.
case openVPNUnsupportedOption = "OpenVPN.unsupportedOption"
case openVPNUnsupportedCompression = "OpenVPN.unsupportedCompression"
/// Configuration has no peers.
case openVPNUnsupportedOption = "OpenVPN.unsupportedOption"
case wireGuardEmptyPeers = "WireGuard.emptyPeers"
}
5 changes: 4 additions & 1 deletion cross/android/io/partout/models/PartoutErrorCode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import kotlinx.serialization.Serializable
/**
*
*
* Values: cached,notFound,operationCancelled,releasedObject,scriptException,timeout,unhandled,incompatibleModules,incompleteModule,noActiveModules,nonFinalModules,requiredImplementation,unexpectedModuleType,unknownImportedModule,unknownModuleHandler,authentication,crypto,dnsFailure,exhaustedEndpoints,fdUnavailable,ioFailure,linkNotActive,networkChanged,networkUnreachable,socketConfiguration,tunNotActive,tunNotAvailable,decoding,encoding,invalidField,invalidValue,parsing,keychainAddItem,keychainItemNotFound,openVPNCompressionMismatch,openVPNConnectionFailure,openVPNNoRouting,openVPNOTPRequired,openVPNPassphraseRequired,openVPNRecoverableAuthentication,openVPNServerShutdown,openVPNTLSFailure,openVPNUnsupportedAlgorithm,openVPNUnsupportedCompression,openVPNUnsupportedOption,wireGuardEmptyPeers
* Values: cached,notFound,operationCancelled,releasedObject,scriptException,timeout,unhandled,incompatibleModules,incompleteModule,noActiveModules,nonFinalModules,requiredImplementation,unexpectedModuleType,unknownImportedModule,unknownModuleHandler,authentication,crypto,dnsFailure,exhaustedEndpoints,fdUnavailable,ioFailure,linkNotActive,networkChanged,networkUnreachable,socketConfiguration,tunNotActive,tunNotAvailable,decoding,encoding,invalidField,invalidValue,parsing,keychainAddItem,keychainItemNotFound,passphraseRequired,openVPNCompressionMismatch,openVPNConnectionFailure,openVPNNoRouting,openVPNOTPRequired,openVPNPassphraseRequired,openVPNRecoverableAuthentication,openVPNServerShutdown,openVPNTLSFailure,openVPNUnsupportedAlgorithm,openVPNUnsupportedCompression,openVPNUnsupportedOption,wireGuardEmptyPeers
*/
@Serializable
enum class PartoutErrorCode(val value: kotlin.String) {
Expand Down Expand Up @@ -138,6 +138,9 @@ enum class PartoutErrorCode(val value: kotlin.String) {
@SerialName(value = "keychainItemNotFound")
keychainItemNotFound("keychainItemNotFound"),

@SerialName(value = "passphraseRequired")
passphraseRequired("passphraseRequired"),

@SerialName(value = "OpenVPN.compressionMismatch")
openVPNCompressionMismatch("OpenVPN.compressionMismatch"),

Expand Down
2 changes: 2 additions & 0 deletions scripts/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ components:
- parsing
- keychainAddItem
- keychainItemNotFound
- passphraseRequired
- OpenVPN.compressionMismatch
- OpenVPN.connectionFailure
- OpenVPN.noRouting
Expand Down Expand Up @@ -839,6 +840,7 @@ components:
- parsing
- keychainAddItem
- keychainItemNotFound
- passphraseRequired
- openVPNCompressionMismatch
- openVPNConnectionFailure
- openVPNNoRouting
Expand Down
2 changes: 1 addition & 1 deletion zig/src/abi/helpers.zig
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ fn boundEventsBinding(ptr: *anyopaque) ?c.partout_daemon_events {
return self.binding;
}

fn eventKeyString(key: net.DaemonEventKey) []const u8 {
fn eventKeyString(key: net.DaemonEventKey) [:0]const u8 {
return switch (key) {
.connection_status => "connectionStatus",
.data_count => "dataCount",
Expand Down
7 changes: 5 additions & 2 deletions zig/src/core/api.zig
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ pub const parseModule = extensions.parseModule;
pub const typeBuildsConnection = extensions.typeBuildsConnection;

// ZIGME: Map errors to code enum (LLM: don't touch this)
pub fn codeForError(_: anyerror) PartoutErrorCode {
return .unhandled;
pub fn codeForError(err: anyerror) PartoutErrorCode {
return switch (err) {
error.PassphraseRequired => .passphraseRequired,
else => .unhandled,
};
}
35 changes: 19 additions & 16 deletions zig/src/core/api_generated.zig
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ pub const ConnectionStatus = enum {
return null;
}

pub fn raw(self: @This()) []const u8 {
pub fn raw(self: @This()) [:0]const u8 {
return switch (self) {
.disconnected => "disconnected",
.connecting => "connecting",
Expand Down Expand Up @@ -498,7 +498,7 @@ pub const DNSModuleDomainPolicy = enum {
return null;
}

pub fn raw(self: @This()) []const u8 {
pub fn raw(self: @This()) [:0]const u8 {
return switch (self) {
.match => "match",
.matchAndSearch => "matchAndSearch",
Expand Down Expand Up @@ -736,7 +736,7 @@ pub const DNSProtocol = enum {
return null;
}

pub fn raw(self: @This()) []const u8 {
pub fn raw(self: @This()) [:0]const u8 {
return switch (self) {
.cleartext => "cleartext",
.https => "https",
Expand Down Expand Up @@ -1014,7 +1014,7 @@ pub const IPSocketType = enum {
return null;
}

pub fn raw(self: @This()) []const u8 {
pub fn raw(self: @This()) [:0]const u8 {
return switch (self) {
.udp => "UDP",
.tcp => "TCP",
Expand Down Expand Up @@ -1061,7 +1061,7 @@ pub const ModuleType = enum {
return null;
}

pub fn raw(self: @This()) []const u8 {
pub fn raw(self: @This()) [:0]const u8 {
return switch (self) {
.Custom => "Custom",
.DNS => "DNS",
Expand Down Expand Up @@ -1155,7 +1155,7 @@ pub const OnDemandModuleOtherNetwork = enum {
return null;
}

pub fn raw(self: @This()) []const u8 {
pub fn raw(self: @This()) [:0]const u8 {
return switch (self) {
.mobile => "mobile",
.ethernet => "ethernet",
Expand Down Expand Up @@ -1184,7 +1184,7 @@ pub const OnDemandModulePolicy = enum {
return null;
}

pub fn raw(self: @This()) []const u8 {
pub fn raw(self: @This()) [:0]const u8 {
return switch (self) {
.any => "any",
.including => "including",
Expand Down Expand Up @@ -1220,7 +1220,7 @@ pub const OpenVPNCipher = enum {
return null;
}

pub fn raw(self: @This()) []const u8 {
pub fn raw(self: @This()) [:0]const u8 {
return switch (self) {
.aes128cbc => "AES-128-CBC",
.aes192cbc => "AES-192-CBC",
Expand Down Expand Up @@ -1709,7 +1709,7 @@ pub const OpenVPNCredentialsOTPMethod = enum {
return null;
}

pub fn raw(self: @This()) []const u8 {
pub fn raw(self: @This()) [:0]const u8 {
return switch (self) {
.none => "none",
.append => "append",
Expand Down Expand Up @@ -1743,7 +1743,7 @@ pub const OpenVPNDigest = enum {
return null;
}

pub fn raw(self: @This()) []const u8 {
pub fn raw(self: @This()) [:0]const u8 {
return switch (self) {
.sha1 => "SHA1",
.sha224 => "SHA224",
Expand Down Expand Up @@ -2034,7 +2034,7 @@ pub const OpenVPNPullMask = enum {
return null;
}

pub fn raw(self: @This()) []const u8 {
pub fn raw(self: @This()) [:0]const u8 {
return switch (self) {
.routes => "routes",
.dns => "dns",
Expand Down Expand Up @@ -2064,7 +2064,7 @@ pub const OpenVPNRoutingPolicy = enum {
return null;
}

pub fn raw(self: @This()) []const u8 {
pub fn raw(self: @This()) [:0]const u8 {
return switch (self) {
.IPv4 => "IPv4",
.IPv6 => "IPv6",
Expand Down Expand Up @@ -2232,7 +2232,7 @@ pub const OpenVPNTLSWrapStrategy = enum {
return null;
}

pub fn raw(self: @This()) []const u8 {
pub fn raw(self: @This()) [:0]const u8 {
return switch (self) {
.auth => "auth",
.crypt => "crypt",
Expand Down Expand Up @@ -2346,6 +2346,7 @@ pub const PartoutErrorCode = enum {
parsing,
keychainAddItem,
keychainItemNotFound,
passphraseRequired,
openVPNCompressionMismatch,
openVPNConnectionFailure,
openVPNNoRouting,
Expand Down Expand Up @@ -2399,6 +2400,7 @@ pub const PartoutErrorCode = enum {
if (std.mem.eql(u8, raw_value, "parsing")) return .parsing;
if (std.mem.eql(u8, raw_value, "keychainAddItem")) return .keychainAddItem;
if (std.mem.eql(u8, raw_value, "keychainItemNotFound")) return .keychainItemNotFound;
if (std.mem.eql(u8, raw_value, "passphraseRequired")) return .passphraseRequired;
if (std.mem.eql(u8, raw_value, "OpenVPN.compressionMismatch")) return .openVPNCompressionMismatch;
if (std.mem.eql(u8, raw_value, "OpenVPN.connectionFailure")) return .openVPNConnectionFailure;
if (std.mem.eql(u8, raw_value, "OpenVPN.noRouting")) return .openVPNNoRouting;
Expand All @@ -2414,7 +2416,7 @@ pub const PartoutErrorCode = enum {
return null;
}

pub fn raw(self: @This()) []const u8 {
pub fn raw(self: @This()) [:0]const u8 {
return switch (self) {
.cached => "cached",
.notFound => "notFound",
Expand Down Expand Up @@ -2450,6 +2452,7 @@ pub const PartoutErrorCode = enum {
.parsing => "parsing",
.keychainAddItem => "keychainAddItem",
.keychainItemNotFound => "keychainItemNotFound",
.passphraseRequired => "passphraseRequired",
.openVPNCompressionMismatch => "OpenVPN.compressionMismatch",
.openVPNConnectionFailure => "OpenVPN.connectionFailure",
.openVPNNoRouting => "OpenVPN.noRouting",
Expand Down Expand Up @@ -2672,7 +2675,7 @@ pub const SocketType = enum {
return null;
}

pub fn raw(self: @This()) []const u8 {
pub fn raw(self: @This()) [:0]const u8 {
return switch (self) {
.udp => "UDP",
.tcp => "TCP",
Expand Down Expand Up @@ -3068,7 +3071,7 @@ pub const TunnelStatus = enum {
return null;
}

pub fn raw(self: @This()) []const u8 {
pub fn raw(self: @This()) [:0]const u8 {
return switch (self) {
.inactive => "inactive",
.activating => "activating",
Expand Down
4 changes: 2 additions & 2 deletions zig/src/core/api_manual.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ pub const Address = struct {
};
}

fn ofZ(c_address: [*:0]const u8) Family {
return ofRaw(std.mem.span(c_address));
fn ofZ(c_address: [:0]const u8) Family {
return ofRaw(c_address);
}

fn isValidPrefixLength(self: Family, prefix_length: u8) bool {
Expand Down
58 changes: 34 additions & 24 deletions zig/src/core/logging.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ var mutex: concurrency.Mutex = .{};
var logs_private_data: bool = false;
var external_logger: Callback = null;

// ZIGME: Suppress until only Zig ABI
// FIXME: #527, Suppress until only Zig ABI
/// C ABI entry point used by foreign callers to forward a log message.
// pub export fn partout_log(
// level: c_int,
Expand All @@ -43,17 +43,9 @@ var external_logger: Callback = null;
// return;
// };
// mutex.unlock();
// dispatch(logger, level, message);
// dispatchCString(logger, level, message);
// }

fn dispatch(
logger: Logger,
level: c_int,
message: [*:0]const u8,
) void {
logger(level, message);
}

/// Configures global logging state.
///
/// `private_data` records whether callers permit sensitive values in logs.
Expand Down Expand Up @@ -97,24 +89,15 @@ pub fn sensitive(value: anytype) SensitiveValue(@TypeOf(value)) {

/// Writes a core log message.
///
/// Messages are dropped when no logger is installed or when allocating the
/// zero-terminated copy fails.
pub fn write(level: Level, message: []const u8) void {
/// The borrowed message remains valid for the duration of the callback.
pub fn write(level: Level, message: [:0]const u8) void {
mutex.lock();
const logger = external_logger orelse {
mutex.unlock();
return;
};
mutex.unlock();
writeTo(logger, level, message);
}

fn writeTo(logger: Logger, level: Level, message: []const u8) void {
const allocator = std.heap.c_allocator;
var c_message: util.TemporaryCString = .{};
c_message.init(allocator, message) catch return;
defer c_message.deinit();
dispatch(logger, @intFromEnum(level), c_message.ptr());
dispatchSlice(logger, @intFromEnum(level), message);
}

/// Formats and writes a core log message.
Expand All @@ -139,8 +122,35 @@ pub fn writef(level: Level, comptime fmt: []const u8, args: anytype) void {
args,
private_data,
) catch return;
const message = std.fmt.allocPrint(allocator, fmt, prepared) catch return;
writeTo(logger, level, message);
const message = std.fmt.allocPrintSentinel(allocator, fmt, prepared, 0) catch return;
dispatchSlice(logger, @intFromEnum(level), message);
}

/// Forwards a borrowed C string directly to the configured C logger.
pub fn writeCString(level: Level, message: [*:0]const u8) void {
mutex.lock();
const logger = external_logger orelse {
mutex.unlock();
return;
};
mutex.unlock();
dispatchCString(logger, @intFromEnum(level), message);
}

fn dispatchSlice(
logger: Logger,
level: c_int,
message: [:0]const u8,
) void {
dispatchCString(logger, level, message.ptr);
}

fn dispatchCString(
logger: Logger,
level: c_int,
message: [*:0]const u8,
) void {
logger(level, message);
}

/// Writes a duration in seconds using a compact `h`, `m`, and `s`
Expand Down
Loading
Loading