Skip to content

Commit

Permalink
generate error code constants for all platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
youyuanwu committed Dec 7, 2024
1 parent bee073b commit 3d7f4e7
Show file tree
Hide file tree
Showing 11 changed files with 311 additions and 5 deletions.
Empty file.
1 change: 1 addition & 0 deletions .metadata/MsQuic.Win32.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "MsQuic.Win32.h"
42 changes: 42 additions & 0 deletions .metadata/MsQuic.Win32.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "winerror.h"
#define QUIC_TLS_ALERT_HRESULT_PREFIX _HRESULT_TYPEDEF_(0x80410100L)

typedef enum {
QUIC_STATUS_SUCCESS = 0x0, // S_OK
QUIC_STATUS_PENDING = 0x703e5, // SUCCESS_HRESULT_FROM_WIN32(ERROR_IO_PENDING)
QUIC_STATUS_CONTINUE = 0x704de, // SUCCESS_HRESULT_FROM_WIN32(ERROR_CONTINUE)
QUIC_STATUS_OUT_OF_MEMORY = 0x8007000e, // E_OUTOFMEMORY
QUIC_STATUS_INVALID_PARAMETER = 0x80070057, // E_INVALIDARG
QUIC_STATUS_INVALID_STATE = 0x8007139f, // E_NOT_VALID_STATE
QUIC_STATUS_NOT_SUPPORTED = 0x80004002, // E_NOINTERFACE
QUIC_STATUS_NOT_FOUND = 0x80070490, // HRESULT_FROM_WIN32(ERROR_NOT_FOUND)
QUIC_STATUS_BUFFER_TOO_SMALL = 0x8007007a, // E_NOT_SUFFICIENT_BUFFER
QUIC_STATUS_HANDSHAKE_FAILURE = 0x80410000, // ERROR_QUIC_HANDSHAKE_FAILURE
QUIC_STATUS_ABORTED = 0x80004004, // E_ABORT
QUIC_STATUS_ADDRESS_IN_USE = 0x80072740, // HRESULT_FROM_WIN32(WSAEADDRINUSE)
QUIC_STATUS_INVALID_ADDRESS = 0x80072741, // HRESULT_FROM_WIN32(WSAEADDRNOTAVAIL)
QUIC_STATUS_CONNECTION_TIMEOUT = 0x80410006, // ERROR_QUIC_CONNECTION_TIMEOUT
QUIC_STATUS_CONNECTION_IDLE = 0x80410005, // ERROR_QUIC_CONNECTION_IDLE
QUIC_STATUS_UNREACHABLE = 0x800704d0, // HRESULT_FROM_WIN32(ERROR_HOST_UNREACHABLE)
QUIC_STATUS_INTERNAL_ERROR = 0x80410003, // ERROR_QUIC_INTERNAL_ERROR
QUIC_STATUS_CONNECTION_REFUSED = 0x800704c9, // HRESULT_FROM_WIN32(ERROR_CONNECTION_REFUSED)
QUIC_STATUS_PROTOCOL_ERROR = 0x80410004, // ERROR_QUIC_PROTOCOL_VIOLATION
QUIC_STATUS_VER_NEG_ERROR = 0x80410001, // ERROR_QUIC_VER_NEG_FAILURE
QUIC_STATUS_TLS_ERROR = 0x80072b18, // HRESULT_FROM_WIN32(WSA_SECURE_HOST_NOT_FOUND)
QUIC_STATUS_USER_CANCELED = 0x80410002, // ERROR_QUIC_USER_CANCELED
QUIC_STATUS_ALPN_NEG_FAILURE = 0x80410007, // ERROR_QUIC_ALPN_NEG_FAILURE
QUIC_STATUS_STREAM_LIMIT_REACHED = 0x80410008, // ERROR_QUIC_STREAM_LIMIT_REACHED
QUIC_STATUS_ALPN_IN_USE = 0x80410009, // ERROR_QUIC_ALPN_IN_USE

QUIC_STATUS_CLOSE_NOTIFY = QUIC_TLS_ALERT_HRESULT_PREFIX | (0xff & 0), // QUIC_STATUS_TLS_ALERT(0) - Close notify
QUIC_STATUS_BAD_CERTIFICATE = QUIC_TLS_ALERT_HRESULT_PREFIX | (0xff & 42), // QUIC_STATUS_TLS_ALERT(42) - Bad Certificate
QUIC_STATUS_UNSUPPORTED_CERTIFICATE = QUIC_TLS_ALERT_HRESULT_PREFIX | (0xff & 43), // QUIC_STATUS_TLS_ALERT(43) - Unsupported Certificate
QUIC_STATUS_REVOKED_CERTIFICATE = QUIC_TLS_ALERT_HRESULT_PREFIX | (0xff & 44), // QUIC_STATUS_TLS_ALERT(44) - Revoked Certificate
QUIC_STATUS_EXPIRED_CERTIFICATE = QUIC_TLS_ALERT_HRESULT_PREFIX | (0xff & 45), // QUIC_STATUS_TLS_ALERT(45) - Expired Certificate
QUIC_STATUS_UNKNOWN_CERTIFICATE = QUIC_TLS_ALERT_HRESULT_PREFIX | (0xff & 46), // QUIC_STATUS_TLS_ALERT(46) - Unknown Certificate
QUIC_STATUS_REQUIRED_CERTIFICATE = QUIC_TLS_ALERT_HRESULT_PREFIX | (0xff & 116), // QUIC_STATUS_TLS_ALERT(116) - Required Certificate

QUIC_STATUS_CERT_EXPIRED = 0xBEBC401, // CERT_E_EXPIRED
QUIC_STATUS_CERT_UNTRUSTED_ROOT = 0xBEBC402, // CERT_E_UNTRUSTEDROOT
QUIC_STATUS_CERT_NO_CERT = 0xBEBC403 // SEC_E_NO_CREDENTIALS
} QUIC_STATUS;
15 changes: 14 additions & 1 deletion .metadata/generate.proj
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,26 @@
</PropertyGroup>
<ItemGroup>
<ScraperRsp Include="scraper.settings.rsp"/>
<ConstantsScraperRsp Include="ConstantsScraper.settings.rsp"/>
</ItemGroup>
<ItemGroup>
<ImportLibs Include="..\build\_deps\msquic_release-src\lib\msquic.lib" />
<Partition Include="MsQuic.c">
<TraverseFiles>..\build\_deps\msquic_release-src\include\msquic.h;..\build\_deps\msquic_release-src\include\msqiuc_winuser.h</TraverseFiles>
<TraverseFiles>..\build\_deps\msquic_release-src\include\msquic.h;</TraverseFiles>
<Namespace>Microsoft.MsQuic</Namespace>
</Partition>
<Partition Include="MsQuic.Win32.c">
<TraverseFiles>MsQuic.Win32.h</TraverseFiles>
<Namespace>Microsoft.MsQuic.Win32</Namespace>
</Partition>
<Partition Include="./linux/MsQuic.Linux.c">
<TraverseFiles>./linux/MsQuic.Linux.h</TraverseFiles>
<Namespace>Microsoft.MsQuic.Linux</Namespace>
</Partition>
<Partition Include="./macos/MsQuic.MacOs.c">
<TraverseFiles>./macos/MsQuic.MacOs.h</TraverseFiles>
<Namespace>Microsoft.MsQuic.MacOs</Namespace>
</Partition>
</ItemGroup>
<Target Name="CopyWin32Metadata" AfterTargets="Build">
<Copy
Expand Down
1 change: 1 addition & 0 deletions .metadata/linux/MsQuic.Linux.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "MsQuic.Linux.h"
44 changes: 44 additions & 0 deletions .metadata/linux/MsQuic.Linux.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#define ERROR_BASE 200000000 // 0xBEBC200
#define TLS_ERROR_BASE 256 + ERROR_BASE // 0xBEBC300
#define CERT_ERROR_BASE 512 + ERROR_BASE // 0xBEBC400

typedef enum {
QUIC_STATUS_SUCCESS = 0, // 0
QUIC_STATUS_PENDING = -2, // -2
QUIC_STATUS_CONTINUE = -1, // -1
QUIC_STATUS_OUT_OF_MEMORY = 12, // 12
QUIC_STATUS_INVALID_PARAMETER = 22, // 22
QUIC_STATUS_INVALID_STATE = 1, // 1
QUIC_STATUS_NOT_SUPPORTED = 95, // 95 (102 on macOS)
QUIC_STATUS_NOT_FOUND = 2, // 2
QUIC_STATUS_BUFFER_TOO_SMALL = 75, // 75 (84 on macOS)
QUIC_STATUS_HANDSHAKE_FAILURE = 103, // 103 (53 on macOS)
QUIC_STATUS_ABORTED = 125, // 125 (89 on macOS)
QUIC_STATUS_ADDRESS_IN_USE = 98, // 98 (48 on macOS)
QUIC_STATUS_INVALID_ADDRESS = 97, // 97 (47 on macOS)
QUIC_STATUS_CONNECTION_TIMEOUT = 110, // 110 (60 on macOS)
QUIC_STATUS_CONNECTION_IDLE = 62, // 62 (101 on macOS)
QUIC_STATUS_INTERNAL_ERROR = 5, // 5
QUIC_STATUS_CONNECTION_REFUSED = 111, // 111 (61 on macOS)
QUIC_STATUS_PROTOCOL_ERROR = 71, // 71 (100 on macOS)
QUIC_STATUS_VER_NEG_ERROR = 93, // 93 (43 on macOS)
QUIC_STATUS_UNREACHABLE = 113, // 113 (65 on macOS)
QUIC_STATUS_TLS_ERROR = 126, // 126
QUIC_STATUS_USER_CANCELED = 130, // 130 (105 on macOS)
QUIC_STATUS_ALPN_NEG_FAILURE = 92, // 92 (42 on macOS)
QUIC_STATUS_STREAM_LIMIT_REACHED = 86, // 86
QUIC_STATUS_ALPN_IN_USE = 91, // 91 (41 on macOS)
QUIC_STATUS_ADDRESS_NOT_AVAILABLE = 99, // 99 (47 on macOS)

QUIC_STATUS_CLOSE_NOTIFY = (0xff & 0) + TLS_ERROR_BASE, // 0xBEBC300 - Close notify
QUIC_STATUS_BAD_CERTIFICATE = (0xff & 42) + TLS_ERROR_BASE, // 0xBEBC32A - Bad Certificate
QUIC_STATUS_UNSUPPORTED_CERTIFICATE = (0xff & 43) + TLS_ERROR_BASE, // 0xBEBC32B - Unsupported Certificate
QUIC_STATUS_REVOKED_CERTIFICATE = (0xff & 44) + TLS_ERROR_BASE, // 0xBEBC32C - Revoked Certificate
QUIC_STATUS_EXPIRED_CERTIFICATE = (0xff & 45) + TLS_ERROR_BASE, // 0xBEBC32D - Expired Certificate
QUIC_STATUS_UNKNOWN_CERTIFICATE = (0xff & 46) + TLS_ERROR_BASE, // 0xBEBC32E - Unknown Certificate
QUIC_STATUS_REQUIRED_CERTIFICATE = (0xff & 116) + TLS_ERROR_BASE, // 0xBEBC374 - Required Certificate

QUIC_STATUS_CERT_EXPIRED = 1 + CERT_ERROR_BASE, // 0xBEBC401
QUIC_STATUS_CERT_UNTRUSTED_ROOT = 2 + CERT_ERROR_BASE, // 0xBEBC402
QUIC_STATUS_CERT_NO_CERT = 3 + CERT_ERROR_BASE, // 0xBEBC403
} QUIC_STATUS;
1 change: 1 addition & 0 deletions .metadata/macos/MsQuic.MacOs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "MsQuic.MacOs.h"
44 changes: 44 additions & 0 deletions .metadata/macos/MsQuic.MacOs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#define ERROR_BASE 200000000 // 0xBEBC200
#define TLS_ERROR_BASE 256 + ERROR_BASE // 0xBEBC300
#define CERT_ERROR_BASE 512 + ERROR_BASE // 0xBEBC400

typedef enum {
QUIC_STATUS_SUCCESS = 0, // 0
QUIC_STATUS_PENDING = -2, // -2
QUIC_STATUS_CONTINUE = -1, // -1
QUIC_STATUS_OUT_OF_MEMORY = 12, // 12
QUIC_STATUS_INVALID_PARAMETER = 22, // 22
QUIC_STATUS_INVALID_STATE = 1, // 1
QUIC_STATUS_NOT_SUPPORTED = 102, // 102 (95 on Linux)
QUIC_STATUS_NOT_FOUND = 2, // 2
QUIC_STATUS_BUFFER_TOO_SMALL = 84, // 84 (75 on Linux)
QUIC_STATUS_HANDSHAKE_FAILURE = 53, // 53 (103 on Linux)
QUIC_STATUS_ABORTED = 89, // 89 (125 on Linux)
QUIC_STATUS_ADDRESS_IN_USE = 48, // 48 (98 on Linux)
QUIC_STATUS_INVALID_ADDRESS = 47, // 47 (97 on Linux)
QUIC_STATUS_CONNECTION_TIMEOUT = 60, // 60 (110 on Linux)
QUIC_STATUS_CONNECTION_IDLE = 101, // 101 (62 on Linux)
QUIC_STATUS_INTERNAL_ERROR = 5, // 5
QUIC_STATUS_CONNECTION_REFUSED = 61, // 61 (111 on Linux)
QUIC_STATUS_PROTOCOL_ERROR = 100, // 100 (71 on Linux)
QUIC_STATUS_VER_NEG_ERROR = 43, // 43 (93 on Linux)
QUIC_STATUS_UNREACHABLE = 65, // 65 (113 on Linux)
QUIC_STATUS_TLS_ERROR = 126, // 126
QUIC_STATUS_USER_CANCELED = 105, // 105 (130 on Linux)
QUIC_STATUS_ALPN_NEG_FAILURE = 42, // 42 (92 on Linux)
QUIC_STATUS_STREAM_LIMIT_REACHED = 86, // 86
QUIC_STATUS_ALPN_IN_USE = 41, // 41 (91 on Linux)
QUIC_STATUS_ADDRESS_NOT_AVAILABLE = 47, // 47 (99 on Linux)

QUIC_STATUS_CLOSE_NOTIFY = (0xff & 0) + TLS_ERROR_BASE, // 0xBEBC300 - Close notify
QUIC_STATUS_BAD_CERTIFICATE = (0xff & 42) + TLS_ERROR_BASE, // 0xBEBC32A - Bad Certificate
QUIC_STATUS_UNSUPPORTED_CERTIFICATE = (0xff & 43) + TLS_ERROR_BASE, // 0xBEBC32B - Unsupported Certificate
QUIC_STATUS_REVOKED_CERTIFICATE = (0xff & 44) + TLS_ERROR_BASE, // 0xBEBC32C - Revoked Certificate
QUIC_STATUS_EXPIRED_CERTIFICATE = (0xff & 45) + TLS_ERROR_BASE, // 0xBEBC32D - Expired Certificate
QUIC_STATUS_UNKNOWN_CERTIFICATE = (0xff & 46) + TLS_ERROR_BASE, // 0xBEBC32E - Unknown Certificate
QUIC_STATUS_REQUIRED_CERTIFICATE = (0xff & 116) + TLS_ERROR_BASE, // 0xBEBC374 - Required Certificate

QUIC_STATUS_CERT_EXPIRED = 1 + CERT_ERROR_BASE, // 0xBEBC401
QUIC_STATUS_CERT_UNTRUSTED_ROOT = 2 + CERT_ERROR_BASE, // 0xBEBC402
QUIC_STATUS_CERT_NO_CERT = 3 + CERT_ERROR_BASE, // 0xBEBC403
} QUIC_STATUS;
Binary file modified .windows/winmd/Microsoft.MsQuic.winmd
Binary file not shown.
19 changes: 15 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ cmake_minimum_required(VERSION 3.16)
project(msquic-asio LANGUAGES)

set(_msquic_version "v2.4.5")

set(_win_pkg_url "https://github.com/microsoft/msquic/releases/download/${_msquic_version}/msquic_windows_x64_Release_schannel.zip")
set(_linux_pkg_url "https://github.com/microsoft/msquic/releases/download/${_msquic_version}/msquic_linux_x64_Release_openssl.zip")
if(WIN32)
set(release_url "https://github.com/microsoft/msquic/releases/download/${_msquic_version}/msquic_windows_x64_Release_schannel.zip")
set(release_url ${_win_pkg_url})
else()
# linux
set(release_url "https://github.com/microsoft/msquic/releases/download/${_msquic_version}/msquic_linux_x64_Release_openssl.zip")
set(release_url ${_linux_pkg_url})
find_package(OpenSSL REQUIRED)
# openssl needs version 1.1. ubuntu 20.04 has it, 22.04 is too new.
endif(WIN32)
Expand All @@ -20,9 +21,19 @@ FetchContent_Declare(
DOWNLOAD_EXTRACT_TIMESTAMP true
URL ${release_url}
)

FetchContent_MakeAvailable(msquic_release)

# fetch linux pkg as well on windows for binding generation
if(WIN32)
message(STATUS "fetching msquic_linux_release " ${_linux_pkg_url})
FetchContent_Declare(
msquic_linux_release
DOWNLOAD_EXTRACT_TIMESTAMP true
URL ${_linux_pkg_url}
)
FetchContent_MakeAvailable(msquic_linux_release)
endif(WIN32)

if(WIN32)
# generate winmd. defer generation task in .metadata csproj.
find_program (
Expand Down
Loading

0 comments on commit 3d7f4e7

Please sign in to comment.