diff --git a/.gitignore b/.gitignore index 640d4a5..fa4eb0f 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,5 @@ launchSettings.json .runsettings Samples/Properties TestProject/Properties +.run +ZitiNativeApiForDotnetCore/Testing/ diff --git a/OpenZiti.NET/OpenZiti.NET.csproj b/OpenZiti.NET/OpenZiti.NET.csproj index 3daad0d..224ff94 100644 --- a/OpenZiti.NET/OpenZiti.NET.csproj +++ b/OpenZiti.NET/OpenZiti.NET.csproj @@ -53,7 +53,7 @@ - + diff --git a/OpenZiti.NET/OpenZiti.NET.nuspec b/OpenZiti.NET/OpenZiti.NET.nuspec index 01d0635..538d351 100644 --- a/OpenZiti.NET/OpenZiti.NET.nuspec +++ b/OpenZiti.NET/OpenZiti.NET.nuspec @@ -6,7 +6,7 @@ openziti.org OpenZiti Maintainers Apache-2.0 - https://openziti.github.io/ziti-sdk-csharp + https://github.com/openziti/ziti-sdk-csharp images\ziti-v2.png false @@ -22,7 +22,7 @@ - + diff --git a/ZitiNativeApiForDotnetCore/CMakeLists.txt b/ZitiNativeApiForDotnetCore/CMakeLists.txt index e008dcc..9a72a91 100644 --- a/ZitiNativeApiForDotnetCore/CMakeLists.txt +++ b/ZitiNativeApiForDotnetCore/CMakeLists.txt @@ -32,6 +32,7 @@ message("cross-compiling: ${CMAKE_CROSSCOMPILING}") # message(STATUS "CMAKE_ENV: ${_variableName}=${${_variableName}}") #endforeach() +include(FetchContent) add_subdirectory(cmake_deps) add_subdirectory(library) #add_subdirectory(programs) @@ -47,7 +48,6 @@ if("${generate_csharp_enum}" STREQUAL "yes") message("sharp-errors output to: ${OUTPUT_FILE}") endif() -include(FetchContent) string(TOLOWER "${ZITI_RUN_DEFGEN}" ziti_run_defgen) if("${ziti_run_defgen}" STREQUAL "yes") FetchContent_Declare( diff --git a/ZitiNativeApiForDotnetCore/README.md b/ZitiNativeApiForDotnetCore/README.md index 3eb7536..eaadd6d 100644 --- a/ZitiNativeApiForDotnetCore/README.md +++ b/ZitiNativeApiForDotnetCore/README.md @@ -93,6 +93,11 @@ and `URL`. See the CMakeLists.txt file for how it's done. To run the defgen step, when configuring cmake pass: -DZITI_RUN_DEFGEN. It will then invoke `defgen.bat` during the configuration step. If the file changes, **make sure you commit the file**. +Example command to run defgen during the `cmake` configuration step: +``` +cmake --preset win64 -S . -DZITI_RUN_DEFGEN=yes +``` + After it runs, defgen leaves behind three extraneous files: ziti-exports.txt, ziti.dll, ziti.exp. It leaves these files behind in case you need to do deubgging on the process but these files should not be checked in (they are .gitignore'ed). diff --git a/ZitiNativeApiForDotnetCore/includes/ziti4dotnet.h b/ZitiNativeApiForDotnetCore/includes/ziti4dotnet.h index c8ce772..1a38e40 100644 --- a/ZitiNativeApiForDotnetCore/includes/ziti4dotnet.h +++ b/ZitiNativeApiForDotnetCore/includes/ziti4dotnet.h @@ -20,46 +20,104 @@ extern "C" { #endif -#define FIELD_WITH_CHECK(FIELD_TYPE, FIELD_NAME) uint32_t FIELD_NAME##_offset; \ - uint32_t FIELD_NAME##_size; \ - const char* FIELD_NAME##_checksum; \ - FIELD_TYPE FIELD_NAME -typedef struct ziti_types_s { - FIELD_WITH_CHECK(uint32_t, total_size); - - FIELD_WITH_CHECK(ziti_auth_query_mfa, ziti_auth_query_mfa); - FIELD_WITH_CHECK(ziti_id_cfg, ziti_id_cfg); - FIELD_WITH_CHECK(ziti_config, ziti_config); - FIELD_WITH_CHECK(api_path, api_path); - FIELD_WITH_CHECK(ziti_api_versions, ziti_api_versions); - FIELD_WITH_CHECK(ziti_version, ziti_version); - FIELD_WITH_CHECK(ziti_identity, ziti_identity); - FIELD_WITH_CHECK(ziti_process, ziti_process); - FIELD_WITH_CHECK(ziti_posture_query, ziti_posture_query); - FIELD_WITH_CHECK(ziti_posture_query_set, ziti_posture_query_set); - FIELD_WITH_CHECK(ziti_session_type, ziti_session_type); - FIELD_WITH_CHECK(ziti_service, ziti_service); - FIELD_WITH_CHECK(ziti_address, ziti_address_host); - FIELD_WITH_CHECK(ziti_address, ziti_address_cidr); - FIELD_WITH_CHECK(ziti_client_cfg_v1, ziti_client_cfg_v1); - FIELD_WITH_CHECK(ziti_intercept_cfg_v1, ziti_intercept_cfg_v1); - FIELD_WITH_CHECK(ziti_server_cfg_v1, ziti_server_cfg_v1); - FIELD_WITH_CHECK(ziti_listen_options, ziti_listen_options); - FIELD_WITH_CHECK(ziti_host_cfg_v1, ziti_host_cfg_v1); - FIELD_WITH_CHECK(ziti_host_cfg_v2, ziti_host_cfg_v2); - FIELD_WITH_CHECK(ziti_mfa_enrollment, ziti_mfa_enrollment); - FIELD_WITH_CHECK(ziti_port_range, ziti_port_range); - FIELD_WITH_CHECK(ziti_options, ziti_options); - - //events - FIELD_WITH_CHECK(ziti_event_t, ziti_context_event); - FIELD_WITH_CHECK(ziti_event_t, ziti_router_event); - FIELD_WITH_CHECK(ziti_event_t, ziti_service_event); - FIELD_WITH_CHECK(ziti_event_t, ziti_mfa_auth_event); - FIELD_WITH_CHECK(ziti_event_t, ziti_api_event); - - -} ziti_types_t; +#define ALIGNMENT_CHECK(FIELD_TYPE) \ +typedef struct ziti_alignment_check_##FIELD_TYPE##_s { \ + uint32_t offset; \ + uint32_t size; \ + const char* checksum; \ +} ziti_alignment_check_##FIELD_TYPE +#define ALIGNMENT_FIELD(FIELD_TYPE, FIELD_NAME) \ + ziti_alignment_check_##FIELD_TYPE FIELD_NAME + +ALIGNMENT_CHECK(ziti_auth_query_mfa); +ALIGNMENT_CHECK(ziti_id_cfg); +ALIGNMENT_CHECK(ziti_config); +ALIGNMENT_CHECK(api_path); +ALIGNMENT_CHECK(ziti_api_versions); +ALIGNMENT_CHECK(ziti_version); +ALIGNMENT_CHECK(ziti_identity); +ALIGNMENT_CHECK(ziti_process); +ALIGNMENT_CHECK(ziti_posture_query); +ALIGNMENT_CHECK(ziti_posture_query_set); +ALIGNMENT_CHECK(ziti_session_type); +ALIGNMENT_CHECK(ziti_service); +ALIGNMENT_CHECK(ziti_address); +ALIGNMENT_CHECK(ziti_client_cfg_v1); +ALIGNMENT_CHECK(ziti_intercept_cfg_v1); +ALIGNMENT_CHECK(ziti_server_cfg_v1); +ALIGNMENT_CHECK(ziti_listen_options); +ALIGNMENT_CHECK(ziti_host_cfg_v1); +ALIGNMENT_CHECK(ziti_host_cfg_v2); +ALIGNMENT_CHECK(ziti_mfa_enrollment); +ALIGNMENT_CHECK(ziti_port_range); +ALIGNMENT_CHECK(ziti_options); +ALIGNMENT_CHECK(ziti_event_t); + +#define ALIGNMENT_DATA(FIELD_TYPE, FIELD_NAME) \ + FIELD_TYPE FIELD_NAME##_data + +typedef struct ziti_types_v2_s { + uint32_t size; //declare as a pointer but use as a value + // declare all the alignements: offset, size, checksum + ALIGNMENT_FIELD(ziti_auth_query_mfa, ziti_auth_query_mfa); + ALIGNMENT_FIELD(ziti_id_cfg, ziti_id_cfg); + ALIGNMENT_FIELD(ziti_config, ziti_config); + ALIGNMENT_FIELD(api_path, api_path); + ALIGNMENT_FIELD(ziti_api_versions, ziti_api_versions); + ALIGNMENT_FIELD(ziti_version, ziti_version); + ALIGNMENT_FIELD(ziti_identity, ziti_identity); + ALIGNMENT_FIELD(ziti_process, ziti_process); + ALIGNMENT_FIELD(ziti_posture_query, ziti_posture_query); + ALIGNMENT_FIELD(ziti_posture_query_set, ziti_posture_query_set); + ALIGNMENT_FIELD(ziti_session_type, ziti_session_type); + ALIGNMENT_FIELD(ziti_service, ziti_service); + ALIGNMENT_FIELD(ziti_address, ziti_address_host); + ALIGNMENT_FIELD(ziti_address, ziti_address_cidr); + ALIGNMENT_FIELD(ziti_client_cfg_v1, ziti_client_cfg_v1); + ALIGNMENT_FIELD(ziti_intercept_cfg_v1, ziti_intercept_cfg_v1); + ALIGNMENT_FIELD(ziti_server_cfg_v1, ziti_server_cfg_v1); + ALIGNMENT_FIELD(ziti_listen_options, ziti_listen_options); + ALIGNMENT_FIELD(ziti_host_cfg_v1, ziti_host_cfg_v1); + ALIGNMENT_FIELD(ziti_host_cfg_v2, ziti_host_cfg_v2); + ALIGNMENT_FIELD(ziti_mfa_enrollment, ziti_mfa_enrollment); + ALIGNMENT_FIELD(ziti_port_range, ziti_port_range); + ALIGNMENT_FIELD(ziti_options, ziti_options); + ALIGNMENT_FIELD(ziti_event_t, ziti_context_event); + ALIGNMENT_FIELD(ziti_event_t, ziti_router_event); + ALIGNMENT_FIELD(ziti_event_t, ziti_service_event); + ALIGNMENT_FIELD(ziti_event_t, ziti_mfa_auth_event); + ALIGNMENT_FIELD(ziti_event_t, ziti_api_event); + + // now declare "_data" elemnets - the __ACTUAL__ structs + ALIGNMENT_DATA(ziti_auth_query_mfa, ziti_auth_query_mfa); + ALIGNMENT_DATA(ziti_id_cfg, ziti_id_cfg); + ALIGNMENT_DATA(ziti_config, ziti_config); + ALIGNMENT_DATA(api_path, api_path); + ALIGNMENT_DATA(ziti_api_versions, ziti_api_versions); + ALIGNMENT_DATA(ziti_version, ziti_version); + ALIGNMENT_DATA(ziti_identity, ziti_identity); + ALIGNMENT_DATA(ziti_process, ziti_process); + ALIGNMENT_DATA(ziti_posture_query, ziti_posture_query); + ALIGNMENT_DATA(ziti_posture_query_set, ziti_posture_query_set); + ALIGNMENT_DATA(ziti_session_type, ziti_session_type); + ALIGNMENT_DATA(ziti_service, ziti_service); + ALIGNMENT_DATA(ziti_address, ziti_address_host); + ALIGNMENT_DATA(ziti_address, ziti_address_cidr); + ALIGNMENT_DATA(ziti_client_cfg_v1, ziti_client_cfg_v1); + ALIGNMENT_DATA(ziti_intercept_cfg_v1, ziti_intercept_cfg_v1); + ALIGNMENT_DATA(ziti_server_cfg_v1, ziti_server_cfg_v1); + ALIGNMENT_DATA(ziti_listen_options, ziti_listen_options); + ALIGNMENT_DATA(ziti_host_cfg_v1, ziti_host_cfg_v1); + ALIGNMENT_DATA(ziti_host_cfg_v2, ziti_host_cfg_v2); + ALIGNMENT_DATA(ziti_mfa_enrollment, ziti_mfa_enrollment); + ALIGNMENT_DATA(ziti_port_range, ziti_port_range); + ALIGNMENT_DATA(ziti_options, ziti_options); + ALIGNMENT_DATA(ziti_event_t, ziti_context_event); + ALIGNMENT_DATA(ziti_event_t, ziti_router_event); + ALIGNMENT_DATA(ziti_event_t, ziti_service_event); + ALIGNMENT_DATA(ziti_event_t, ziti_mfa_auth_event); + ALIGNMENT_DATA(ziti_event_t, ziti_api_event); +} ziti_types_v2; Z4D_API int z4d_ziti_close(ziti_connection con); Z4D_API int z4d_uv_run(void* loop); @@ -78,7 +136,7 @@ Z4D_API void z4d_free_char_array(char **a, int size); Z4D_API void z4d_ziti_dump_log(ziti_context ztx); Z4D_API void z4d_ziti_dump_file(ziti_context ztx, const char* outputFile); -Z4D_API ziti_types_t* z4d_struct_test(); +Z4D_API ziti_types_v2* z4d_struct_test(); Z4D_API ziti_posture_query* z4d_ziti_posture_query(); typedef void (*z4d_cb)(void* context); @@ -88,4 +146,4 @@ Z4D_API void z4d_callback_on_loop(uv_loop_t* loop, void* context, z4d_cb cb); } #endif -#endif /* ZITI4DOTNET_H */ \ No newline at end of file +#endif /* ZITI4DOTNET_H */ diff --git a/ZitiNativeApiForDotnetCore/library/ziti4dotnet.c b/ZitiNativeApiForDotnetCore/library/ziti4dotnet.c index f1b7524..3619ca2 100644 --- a/ZitiNativeApiForDotnetCore/library/ziti4dotnet.c +++ b/ZitiNativeApiForDotnetCore/library/ziti4dotnet.c @@ -78,22 +78,6 @@ void z4d_free_char_array(char **a, int size) { free(a); } -char* ziti_context_event_err(const ziti_event_t *e) { - if (e && e->event.ctx.err) { - return e->event.ctx.err; - } else { - return NULL; - } -} -const char* ziti_context_event_status(const ziti_event_t* e) { - if (e) { - return e->event.ctx.err; - } - else { - return 0; - } -} - typedef int (*printer)(void* arg, const char* fmt, ...); static int ziti_dump_to_log_op(void* stringsBuilder, const char* fmt, ...) { @@ -182,21 +166,24 @@ void z4d_callback_on_loop(uv_loop_t* loop, void* context, z4d_cb cb) { #define OFFSET(MEMBERNAME) OFFSETNAMED(MEMBERNAME, MEMBERNAME) -#define OFFSETNAMED(MEMBERTYPE, MEMBERNAME) printf("\noffset of ziti_types_t." #MEMBERTYPE "." #MEMBERNAME ": %zu size: %zu", offsetof(ziti_types_t, MEMBERNAME), sizeof(MEMBERTYPE)) +#define OFFSETNAMED(MEMBERTYPE, MEMBERNAME) printf("\noffset of ziti_types_v2." #MEMBERTYPE "." #MEMBERNAME ": %zu size: %zu", offsetof(ziti_types_v2, MEMBERNAME), sizeof(MEMBERTYPE)) #define SUBOFFSET(MEMBERTYPE, CHILD) SUBOFFSETNAMED(MEMBERTYPE, MEMBERTYPE, CHILD) -#define SUBOFFSETNAMED(MEMBERTYPE, MEMBERNAME, CHILD) printf("\noffset of ziti_types_t." #MEMBERNAME "." #CHILD ": %zu.%zu size: %zu", offsetof(ziti_types_t, MEMBERNAME) + offsetof(MEMBERTYPE, CHILD), offsetof(MEMBERTYPE, CHILD), sizeof(MEMBERTYPE)) +#define SUBOFFSETNAMED(MEMBERTYPE, MEMBERNAME, CHILD) printf("\noffset of ziti_types_v2." #MEMBERNAME "." #CHILD ": %zu.%zu size: %zu", offsetof(ziti_types_v2, MEMBERNAME) + offsetof(MEMBERTYPE, CHILD), offsetof(MEMBERTYPE, CHILD), sizeof(MEMBERTYPE)) #define BYTEALIGNCHECK(FIELDNAME) BYTEALIGNCHECKBYTYPE(FIELDNAME, FIELDNAME) -#define BYTEALIGNCHECKBYTYPE(FIELDNAME, FIELDTYPE) rtn->FIELDNAME##_checksum = #FIELDNAME; \ - rtn->FIELDNAME##_offset = offsetof(ziti_types_t, FIELDNAME); \ - rtn->FIELDNAME##_size = sizeof(FIELDTYPE) -ziti_types_t* z4d_struct_test() { - ziti_types_t* rtn = calloc(sizeof(ziti_types_t) + 1, 1); - rtn->total_size = sizeof(ziti_types_t); - rtn->total_size_checksum = "total_size_checksum"; - - OFFSETNAMED(uint32_t, total_size); +#define BYTEALIGNCHECKBYTYPE(FIELDNAME, FIELDTYPE) rtn->FIELDNAME.checksum = #FIELDNAME; \ + rtn->FIELDNAME.offset = offsetof(ziti_types_v2, FIELDNAME); \ + rtn->FIELDNAME.size = sizeof(FIELDTYPE) +typedef struct c_t { + uint32_t size; + ziti_alignment_check_ziti_auth_query_mfa ziti_auth_query_mfa; +} c_s; + +ziti_types_v2* z4d_struct_test() { + ziti_types_v2* rtn = calloc(sizeof(ziti_types_t) + 1, 1); + rtn->size = sizeof(ziti_types_v2); + OFFSET(ziti_auth_query_mfa); OFFSET(ziti_id_cfg); OFFSET(ziti_config); @@ -207,20 +194,11 @@ ziti_types_t* z4d_struct_test() { OFFSET(ziti_process); OFFSET(ziti_posture_query); SUBOFFSETNAMED(ziti_posture_query, ziti_posture_query, id); - SUBOFFSET(ziti_posture_query, is_passing); - SUBOFFSET(ziti_posture_query, query_type); - SUBOFFSET(ziti_posture_query, process); - SUBOFFSET(ziti_posture_query, processes); - SUBOFFSET(ziti_posture_query, timeout); - SUBOFFSET(ziti_posture_query, timeoutRemaining); - SUBOFFSET(ziti_posture_query, updated_at); - OFFSET(ziti_posture_query_set); SUBOFFSET(ziti_posture_query_set, policy_id); SUBOFFSET(ziti_posture_query_set, is_passing); SUBOFFSET(ziti_posture_query_set, policy_type); SUBOFFSET(ziti_posture_query_set, posture_queries); - OFFSETNAMED(char*, ziti_posture_query_set_checksum); OFFSET(ziti_session_type); OFFSET(ziti_service); @@ -243,245 +221,253 @@ ziti_types_t* z4d_struct_test() { OFFSET(ziti_mfa_enrollment); OFFSET(ziti_port_range); - rtn->ziti_auth_query_mfa.type_id = "type"; - rtn->ziti_auth_query_mfa.provider = "provider"; - rtn->ziti_auth_query_mfa.http_method = "http_method"; - rtn->ziti_auth_query_mfa.http_url = "http_url"; - rtn->ziti_auth_query_mfa.min_length = 81; - rtn->ziti_auth_query_mfa.max_length = 92; - rtn->ziti_auth_query_mfa.format = "format"; + rtn->ziti_auth_query_mfa_data.type_id = "type"; + rtn->ziti_auth_query_mfa_data.provider = "provider"; + rtn->ziti_auth_query_mfa_data.http_method = "http_method"; + rtn->ziti_auth_query_mfa_data.http_url = "http_url"; + rtn->ziti_auth_query_mfa_data.min_length = 81; + rtn->ziti_auth_query_mfa_data.max_length = 92; + rtn->ziti_auth_query_mfa_data.format = "format"; BYTEALIGNCHECK(ziti_auth_query_mfa); - rtn->ziti_id_cfg.cert = "cert"; - rtn->ziti_id_cfg.key = "key"; - rtn->ziti_id_cfg.ca = "ca"; + rtn->ziti_id_cfg_data.cert = "cert"; + rtn->ziti_id_cfg_data.key = "key"; + rtn->ziti_id_cfg_data.ca = "ca"; BYTEALIGNCHECK(ziti_id_cfg); - rtn->ziti_config.controller_url = "controller_url"; - rtn->ziti_config.id = rtn->ziti_id_cfg; + rtn->ziti_config_data.controller_url = "controller_url"; + rtn->ziti_config_data.id = rtn->ziti_id_cfg_data; BYTEALIGNCHECK(ziti_config); - rtn->api_path.path = "path"; + rtn->api_path_data.path = "path"; BYTEALIGNCHECK(api_path); - model_map_set(&rtn->ziti_api_versions.edge, "edge_key1", "edge_val1"); - model_map_set(&rtn->ziti_api_versions.edge, "edge_key2", "edge_val2"); + model_map_set(&rtn->ziti_api_versions_data.edge, "edge_key1", "edge_val1"); + model_map_set(&rtn->ziti_api_versions_data.edge, "edge_key2", "edge_val2"); BYTEALIGNCHECK(ziti_api_versions); - rtn->ziti_version.version = "version"; - rtn->ziti_version.revision = "revision"; - rtn->ziti_version.build_date = "build_date"; - rtn->ziti_version.api_versions = &rtn->ziti_api_versions; + rtn->ziti_version_data.version = "version"; + rtn->ziti_version_data.revision = "revision"; + rtn->ziti_version_data.build_date = "build_date"; + rtn->ziti_version_data.api_versions = &rtn->ziti_api_versions_data; BYTEALIGNCHECK(ziti_version); - rtn->ziti_identity.id = "id"; - rtn->ziti_identity.name = "name"; - model_map_set(&rtn->ziti_identity.app_data, "app_data_key1", "app_data_val1"); - model_map_set(&rtn->ziti_identity.app_data, "app_data_key2", "app_data_val2"); + rtn->ziti_identity_data.id = "id"; + rtn->ziti_identity_data.name = "name"; + model_map_set(&rtn->ziti_identity_data.app_data, "app_data_key1", "app_data_val1"); + model_map_set(&rtn->ziti_identity_data.app_data, "app_data_key2", "app_data_val2"); BYTEALIGNCHECK(ziti_identity); - rtn->ziti_process.path = "path"; + rtn->ziti_process_data.path = "path"; BYTEALIGNCHECK(ziti_process); - rtn->ziti_posture_query.id = "id"; - rtn->ziti_posture_query.is_passing = true; - rtn->ziti_posture_query.query_type = "query_type"; - rtn->ziti_posture_query.process = &rtn->ziti_process; + rtn->ziti_posture_query_data.id = "id"; + rtn->ziti_posture_query_data.is_passing = true; + rtn->ziti_posture_query_data.query_type = "query_type"; + rtn->ziti_posture_query_data.process = &rtn->ziti_process_data; ziti_process_array zpa = calloc(sizeof(ziti_process), 2); - zpa[0] = &rtn->ziti_process; - rtn->ziti_posture_query.processes = zpa; - rtn->ziti_posture_query.timeout = 10; + zpa[0] = &rtn->ziti_process_data; + rtn->ziti_posture_query_data.processes = zpa; + rtn->ziti_posture_query_data.timeout = 10; int* time_remain = calloc(sizeof(int), 1); *time_remain = 20; - rtn->ziti_posture_query.timeoutRemaining = time_remain; - rtn->ziti_posture_query.updated_at = "updated_at"; + rtn->ziti_posture_query_data.timeoutRemaining = time_remain; + rtn->ziti_posture_query_data.updated_at = "updated_at"; BYTEALIGNCHECK(ziti_posture_query); - rtn->ziti_posture_query_set.policy_id = "policy_id"; - rtn->ziti_posture_query_set.is_passing = true; - rtn->ziti_posture_query_set.policy_type = "policy_type"; + rtn->ziti_posture_query_set_data.policy_id = "policy_id"; + rtn->ziti_posture_query_set_data.is_passing = true; + rtn->ziti_posture_query_set_data.policy_type = "policy_type"; + rtn->ziti_posture_query_set.checksum = "ziti_posture_query_set"; ziti_posture_query_array zpqa = calloc(sizeof(ziti_posture_query), 2); - zpqa[0] = &rtn->ziti_posture_query; - rtn->ziti_posture_query_set.posture_queries = zpqa; + zpqa[0] = &rtn->ziti_posture_query_data; + rtn->ziti_posture_query_set_data.posture_queries = zpqa; ziti_posture_query_set_array zpqsa = calloc(sizeof(ziti_posture_query_set), 2); - zpqsa[0] = &rtn->ziti_posture_query_set; + zpqsa[0] = &rtn->ziti_posture_query_set_data; BYTEALIGNCHECK(ziti_posture_query_set); - rtn->ziti_posture_query_set_checksum = "ziti_posture_query_set"; +// rtn->ziti_posture_query_set_checksum = "ziti_posture_query_set"; - rtn->ziti_session_type = ziti_session_type_Dial; + rtn->ziti_session_type_data = ziti_session_type_Dial; BYTEALIGNCHECK(ziti_session_type); - rtn->ziti_service.id = "id"; + rtn->ziti_service_data.id = "id"; SUBOFFSET(ziti_service, id); - rtn->ziti_service.name = "name"; + rtn->ziti_service_data.name = "name"; SUBOFFSET(ziti_service, name); ziti_session_type_array zsta = calloc(sizeof(ziti_session_type), 2); - zsta[0] = &rtn->ziti_session_type; - rtn->ziti_service.permissions = zsta; + zsta[0] = &rtn->ziti_session_type_data; + rtn->ziti_service_data.permissions = zsta; SUBOFFSET(ziti_service, permissions); - rtn->ziti_service.encryption = "encryption"; + rtn->ziti_service_data.encryption = 1; SUBOFFSET(ziti_service, encryption); - rtn->ziti_service.perm_flags = 214; + rtn->ziti_service_data.perm_flags = 214; SUBOFFSET(ziti_service, perm_flags); - model_map_set(&rtn->ziti_service.config, "config_key1", "config_val1"); - model_map_set(&rtn->ziti_service.config, "config_key2", "config_val2"); + model_map_set(&rtn->ziti_service_data.config, "config_key1", "config_val1"); + model_map_set(&rtn->ziti_service_data.config, "config_key2", "config_val2"); SUBOFFSET(ziti_service, config); - rtn->ziti_service.posture_query_set = zpqsa; + rtn->ziti_service_data.posture_query_set = zpqsa; SUBOFFSET(ziti_service, posture_query_set); - model_map_set(&rtn->ziti_service.posture_query_map, "posture_query_map_key1", "posture_query_map_value1"); - model_map_set(&rtn->ziti_service.posture_query_map, "posture_query_map_key2", "posture_query_map_value2"); + model_map_set(&rtn->ziti_service_data.posture_query_map, "posture_query_map_key1", "posture_query_map_value1"); + model_map_set(&rtn->ziti_service_data.posture_query_map, "posture_query_map_key2", "posture_query_map_value2"); SUBOFFSET(ziti_service, posture_query_map); - rtn->ziti_service.updated_at = "updated_at"; + rtn->ziti_service_data.updated_at = "updated_at"; SUBOFFSET(ziti_service, updated_at); BYTEALIGNCHECK(ziti_service); - rtn->ziti_address_host.type = ziti_address_hostname; - strncpy(rtn->ziti_address_host.addr.hostname, "hostname", 8); + rtn->ziti_address_host_data.type = ziti_address_hostname; + strncpy(rtn->ziti_address_host_data.addr.hostname, "hostname", 8); BYTEALIGNCHECKBYTYPE(ziti_address_host, ziti_address); - rtn->ziti_address_cidr.type = ziti_address_cidr; - rtn->ziti_address_cidr.addr.cidr.af = AF_INET; - rtn->ziti_address_cidr.addr.cidr.bits = 8; + rtn->ziti_address_cidr_data.type = ziti_address_cidr; + rtn->ziti_address_cidr_data.addr.cidr.af = AF_INET; + rtn->ziti_address_cidr_data.addr.cidr.bits = 8; const char *ip6str = "100.200.50.25"; - if (inet_pton(AF_INET, ip6str, &rtn->ziti_address_cidr.addr.cidr.ip) == 1) { + if (inet_pton(AF_INET, ip6str, &rtn->ziti_address_cidr_data.addr.cidr.ip) == 1) { //printf("successfully parsed\n"); } else { printf("failed to parse ip?\n"); } BYTEALIGNCHECK(ziti_address_cidr); - rtn->ziti_client_cfg_v1.hostname = rtn->ziti_address_host; - rtn->ziti_client_cfg_v1.port = 80; + rtn->ziti_client_cfg_v1_data.hostname = rtn->ziti_address_host_data; + rtn->ziti_client_cfg_v1_data.port = 80; BYTEALIGNCHECK(ziti_client_cfg_v1); ziti_protocol zp = ziti_protocol_tcp; - model_list_append(&rtn->ziti_intercept_cfg_v1.protocols, &zp); - model_list_append(&rtn->ziti_intercept_cfg_v1.addresses, &rtn->ziti_address_host); - model_list_append(&rtn->ziti_intercept_cfg_v1.addresses, &rtn->ziti_address_cidr); + model_list_append(&rtn->ziti_intercept_cfg_v1_data.protocols, &zp); + model_list_append(&rtn->ziti_intercept_cfg_v1_data.addresses, &rtn->ziti_address_host); + model_list_append(&rtn->ziti_intercept_cfg_v1_data.addresses, &rtn->ziti_address_cidr); - rtn->ziti_port_range.low = 80; - rtn->ziti_port_range.high = 443; + rtn->ziti_port_range_data.low = 80; + rtn->ziti_port_range_data.high = 443; - model_list_append(&rtn->ziti_intercept_cfg_v1.port_ranges, &rtn->ziti_port_range); - model_map_set(&rtn->ziti_intercept_cfg_v1.dial_options, "key", "value"); - rtn->ziti_intercept_cfg_v1.source_ip = "source_ip"; + model_list_append(&rtn->ziti_intercept_cfg_v1_data.port_ranges, &rtn->ziti_port_range); + model_map_set(&rtn->ziti_intercept_cfg_v1_data.dial_options, "key", "value"); + rtn->ziti_intercept_cfg_v1_data.source_ip = "source_ip"; BYTEALIGNCHECK(ziti_intercept_cfg_v1); - rtn->ziti_server_cfg_v1.protocol = "protocol"; - rtn->ziti_server_cfg_v1.hostname = "hostname"; - rtn->ziti_server_cfg_v1.port = 443; + rtn->ziti_server_cfg_v1_data.protocol = "protocol"; + rtn->ziti_server_cfg_v1_data.hostname = "hostname"; + rtn->ziti_server_cfg_v1_data.port = 443; BYTEALIGNCHECK(ziti_server_cfg_v1); - rtn->ziti_listen_options.bind_with_identity = true; + rtn->ziti_listen_options_data.bind_with_identity = true; duration d = 1000000; - rtn->ziti_listen_options.connect_timeout = d; - rtn->ziti_listen_options.connect_timeout_seconds = 100; - rtn->ziti_listen_options.cost = 9; - rtn->ziti_listen_options.identity = "identity"; - rtn->ziti_listen_options.max_connections = 10; - rtn->ziti_listen_options.precendence = "precedence"; + rtn->ziti_listen_options_data.connect_timeout = d; + rtn->ziti_listen_options_data.connect_timeout_seconds = 100; + rtn->ziti_listen_options_data.cost = 9; + rtn->ziti_listen_options_data.identity = "identity"; + rtn->ziti_listen_options_data.max_connections = 10; + rtn->ziti_listen_options_data.precendence = "precedence"; BYTEALIGNCHECK(ziti_listen_options); - rtn->ziti_host_cfg_v1.protocol = "protocol"; - rtn->ziti_host_cfg_v1.forward_protocol = true; + rtn->ziti_host_cfg_v1_data.protocol = "protocol"; + rtn->ziti_host_cfg_v1_data.forward_protocol = true; string_array apa = calloc(sizeof(char*), 3); apa[0] = "proto1"; apa[1] = "proto2"; - rtn->ziti_host_cfg_v1.allowed_protocols = apa; - rtn->ziti_host_cfg_v1.address = "address"; - rtn->ziti_host_cfg_v1.forward_address = true; + rtn->ziti_host_cfg_v1_data.allowed_protocols = apa; + rtn->ziti_host_cfg_v1_data.address = "address"; + rtn->ziti_host_cfg_v1_data.forward_address = true; ziti_address_array allowadds = calloc(sizeof(ziti_address), 2); - allowadds[0] = &rtn->ziti_address_host; - rtn->ziti_host_cfg_v1.allowed_addresses = allowadds; - rtn->ziti_host_cfg_v1.port = 1090; - rtn->ziti_host_cfg_v1.forward_port = true; + allowadds[0] = &rtn->ziti_address_host_data; + rtn->ziti_host_cfg_v1_data.allowed_addresses = allowadds; + rtn->ziti_host_cfg_v1_data.port = 1090; + rtn->ziti_host_cfg_v1_data.forward_port = true; ziti_port_range_array zpra = calloc(sizeof(ziti_port_range), 2); - zpra[0] = &rtn->ziti_port_range; - rtn->ziti_host_cfg_v1.allowed_port_ranges = zpra; - rtn->ziti_host_cfg_v1.allowed_source_addresses = allowadds; - rtn->ziti_host_cfg_v1.listen_options = &rtn->ziti_listen_options; + zpra[0] = &rtn->ziti_port_range_data; + rtn->ziti_host_cfg_v1_data.allowed_port_ranges = zpra; + rtn->ziti_host_cfg_v1_data.allowed_source_addresses = allowadds; + rtn->ziti_host_cfg_v1_data.listen_options = &rtn->ziti_listen_options_data; BYTEALIGNCHECK(ziti_host_cfg_v1); - model_list_append(&rtn->ziti_host_cfg_v2.terminators, &rtn->ziti_host_cfg_v2); + model_list_append(&rtn->ziti_host_cfg_v2_data.terminators, &rtn->ziti_host_cfg_v2_data); BYTEALIGNCHECK(ziti_host_cfg_v2); - rtn->ziti_mfa_enrollment.is_verified = true; + rtn->ziti_mfa_enrollment_data.is_verified = true; string_array codes = calloc(sizeof(char*), 2); codes[0] = "code1"; - rtn->ziti_mfa_enrollment.recovery_codes = codes; - rtn->ziti_mfa_enrollment.provisioning_url = "provisioningUrl"; + rtn->ziti_mfa_enrollment_data.recovery_codes = codes; + rtn->ziti_mfa_enrollment_data.provisioning_url = "provisioningUrl"; BYTEALIGNCHECK(ziti_mfa_enrollment); BYTEALIGNCHECK(ziti_port_range); - rtn->ziti_options.config = "config"; - rtn->ziti_options.disabled = true; + rtn->ziti_options_data.config = "config"; + rtn->ziti_options_data.disabled = true; SUBOFFSET(ziti_options, disabled); char** cfgs = calloc(sizeof(char*), 2); cfgs[0] = strdup("config1"); cfgs[1] = strdup("config2"); - rtn->ziti_options.config_types = (const char **) cfgs; + rtn->ziti_options_data.config_types = (const char **) cfgs; SUBOFFSET(ziti_options, config_types); - rtn->ziti_options.api_page_size = 232323; + rtn->ziti_options_data.api_page_size = 232323; SUBOFFSET(ziti_options, api_page_size); - rtn->ziti_options.refresh_interval = 3322; + rtn->ziti_options_data.refresh_interval = 3322; SUBOFFSET(ziti_options, refresh_interval); - rtn->ziti_options.metrics_type = EWMA_15m; + rtn->ziti_options_data.metrics_type = EWMA_15m; SUBOFFSET(ziti_options, metrics_type); - rtn->ziti_options.router_keepalive = 111; + rtn->ziti_options_data.router_keepalive = 111; SUBOFFSET(ziti_options, router_keepalive); - rtn->ziti_options.app_ctx = strdup("ctxhere"); + rtn->ziti_options_data.app_ctx = strdup("ctxhere"); SUBOFFSET(ziti_options, app_ctx); - rtn->ziti_options.events = 98; + rtn->ziti_options_data.events = 98; SUBOFFSET(ziti_options, events); BYTEALIGNCHECK(ziti_options); /*type is a ziti_event_type*/ - rtn->ziti_context_event.type = ZitiContextEvent; + rtn->ziti_context_event_data.type = ZitiContextEvent; SUBOFFSETNAMED(ziti_event_t, ziti_context_event, type); - rtn->ziti_context_event.event.ctx.ctrl_status = 245; + rtn->ziti_context_event_data.event.ctx.ctrl_status = 245; SUBOFFSETNAMED(ziti_event_t, ziti_context_event, event.ctx.ctrl_status); - rtn->ziti_context_event.event.ctx.err = "ziti_context_event_err_0__"; + rtn->ziti_context_event_data.event.ctx.err = "ziti_context_event_err_0__"; SUBOFFSETNAMED(ziti_event_t, ziti_context_event, event.ctx.err); BYTEALIGNCHECKBYTYPE(ziti_context_event, ziti_event_t); - rtn->ziti_router_event.type = ZitiRouterEvent; + rtn->ziti_router_event_data.type = ZitiRouterEvent; SUBOFFSETNAMED(ziti_event_t, ziti_router_event, type); - rtn->ziti_router_event.event.router.status = EdgeRouterConnected; + rtn->ziti_router_event_data.event.router.status = EdgeRouterConnected; SUBOFFSETNAMED(ziti_event_t, ziti_router_event, event.router.status); - rtn->ziti_router_event.event.router.name = "ere_name"; + rtn->ziti_router_event_data.event.router.name = "ere_name"; SUBOFFSETNAMED(ziti_event_t, ziti_router_event, event.router.name); - rtn->ziti_router_event.event.router.address = "ere_address"; + rtn->ziti_router_event_data.event.router.address = "ere_address"; SUBOFFSETNAMED(ziti_event_t, ziti_router_event, event.router.address); - rtn->ziti_router_event.event.router.version = "ere_version"; + rtn->ziti_router_event_data.event.router.version = "ere_version"; SUBOFFSETNAMED(ziti_event_t, ziti_router_event, event.router.version); BYTEALIGNCHECKBYTYPE(ziti_router_event, ziti_event_t); - rtn->ziti_service_event.type = ZitiServiceEvent; + rtn->ziti_service_event_data.type = ZitiServiceEvent; SUBOFFSETNAMED(ziti_event_t, ziti_service_event, type); - ziti_service_array list_of_services = calloc(sizeof(ziti_service*), 2); - list_of_services[0] = calloc(sizeof(ziti_service*), 1); - list_of_services[1] = calloc(sizeof(ziti_service*), 1); - list_of_services[0] = &rtn->ziti_service; - list_of_services[1] = &rtn->ziti_service; - rtn->ziti_service_event.event.service.added = list_of_services; + ziti_service_array list_of_services = calloc(sizeof(ziti_service*), 3); + list_of_services[0] = &rtn->ziti_service_data; + ziti_service* elem2 = calloc(sizeof(ziti_service), 1); + list_of_services[0]->name = strdup("elem1"); + list_of_services[0]->id = strdup("elem1id"); + list_of_services[0]->perm_flags = 111; + elem2->name = strdup("elem2"); + elem2->id = strdup("elem2id"); + elem2->perm_flags = 222; + list_of_services[1] = elem2; //&rtn->ziti_service_data; + rtn->ziti_service_event_data.event.service.added = list_of_services; SUBOFFSETNAMED(ziti_event_t, ziti_service_event, event.service.added); - rtn->ziti_service_event.event.service.changed = list_of_services; + rtn->ziti_service_event_data.event.service.changed = list_of_services; SUBOFFSETNAMED(ziti_event_t, ziti_service_event, event.service.changed); - rtn->ziti_service_event.event.service.removed = list_of_services; + rtn->ziti_service_event_data.event.service.removed = list_of_services; SUBOFFSETNAMED(ziti_event_t, ziti_service_event, event.service.removed); BYTEALIGNCHECKBYTYPE(ziti_service_event, ziti_event_t); - rtn->ziti_mfa_auth_event.type = ZitiMfaAuthEvent; + rtn->ziti_mfa_auth_event_data.type = ZitiMfaAuthEvent; SUBOFFSETNAMED(ziti_event_t, ziti_mfa_auth_event, type); - rtn->ziti_mfa_auth_event.event.mfa_auth_event.auth_query_mfa = &rtn->ziti_auth_query_mfa; + rtn->ziti_mfa_auth_event_data.event.mfa_auth_event.auth_query_mfa = &rtn->ziti_auth_query_mfa_data; SUBOFFSETNAMED(ziti_event_t, ziti_mfa_auth_event, event.mfa_auth_event.auth_query_mfa); BYTEALIGNCHECKBYTYPE(ziti_mfa_auth_event, ziti_event_t); - rtn->ziti_api_event.type = ZitiAPIEvent; + rtn->ziti_api_event_data.type = ZitiAPIEvent; SUBOFFSETNAMED(ziti_event_t, ziti_api_event, type); - rtn->ziti_api_event.event.api.new_ctrl_address = "new_ctrl_address"; + rtn->ziti_api_event_data.event.api.new_ctrl_address = "new_ctrl_address"; SUBOFFSETNAMED(ziti_event_t, ziti_api_event, event.api.new_ctrl_address); + rtn->ziti_api_event_data.event.api.new_ca_bundle = "new_ca_bundle"; + SUBOFFSETNAMED(ziti_event_t, ziti_api_event, event.api.new_ca_bundle); BYTEALIGNCHECKBYTYPE(ziti_api_event, ziti_event_t); printf("\noffset output complete\n\n"); @@ -505,4 +491,5 @@ void useUnusedFuncs() { ziti_conn_bridge(NULL, NULL, NULL); ziti_conn_bridge_fds(NULL, NULL, NULL, NULL, NULL); Ziti_lib_init(); -} \ No newline at end of file +} + diff --git a/ZitiNativeApiForDotnetCore/library/zitistructalignment.c b/ZitiNativeApiForDotnetCore/library/zitistructalignment.c index e448c1b..227c94a 100644 --- a/ZitiNativeApiForDotnetCore/library/zitistructalignment.c +++ b/ZitiNativeApiForDotnetCore/library/zitistructalignment.c @@ -3,8 +3,6 @@ int main() { printf("\noffset output begins\n"); - ziti_types_t* rtn = z4d_struct_test(); - printf(rtn->ziti_posture_query_set_checksum); - char* r = model_map_get(&rtn->ziti_service.config, "config_key1"); + ziti_types_v2* rtn = z4d_struct_test(); printf("\noffset output complete\n\n"); } diff --git a/native-package.nuspec b/native-package.nuspec index 0a4e709..29517ab 100644 --- a/native-package.nuspec +++ b/native-package.nuspec @@ -7,7 +7,7 @@ openziti.org OpenZiti Maintainers Apache-2.0 - https://openziti.github.io/ziti-sdk-csharp + https://github.com/openziti/ziti-sdk-csharp ziti-v2.png false A nuget package which wraps the native ziti C SDK into a package easily consumable from .NET