Compare commits
18
Commits
c2b68dea2f
...
v2.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
847308c160 | ||
|
|
fccdb2e159 | ||
|
|
21e158fae0 | ||
|
|
e4f5d88d14 | ||
|
|
a1ee8ef10b | ||
|
|
14b6f7a046 | ||
|
|
efabac6564 | ||
|
|
325b1b9ae8 | ||
|
|
257d2a9971 | ||
|
|
06e06b7622 | ||
|
|
3d61e6952f | ||
|
|
caac928923 | ||
|
|
24075fbd52 | ||
|
|
295542ab9e | ||
|
|
e7573fbcd0 | ||
|
|
97dc183bdf | ||
|
|
dede07748a | ||
|
|
222aee8889 |
No files matched your search
@@ -0,0 +1,55 @@
|
|||||||
|
name: Independent component release
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags: [v*]
|
||||||
|
schedule:
|
||||||
|
- cron: '17 2 * * *'
|
||||||
|
workflow_dispatch:
|
||||||
|
jobs:
|
||||||
|
publish:
|
||||||
|
runs-on: echoion-release-serial
|
||||||
|
steps:
|
||||||
|
- name: Check out component
|
||||||
|
uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Check out pinned public release tools
|
||||||
|
uses: https://github.com/actions/checkout@11d5960a326750d5838078e36cf38b85af677262
|
||||||
|
with:
|
||||||
|
repository: Void/Echoion
|
||||||
|
ref: ${{ vars.ECHOION_RELEASE_TOOLS_REF }}
|
||||||
|
path: .echoion-release-tools
|
||||||
|
fetch-depth: 0
|
||||||
|
persist-credentials: false
|
||||||
|
- name: Build, publish, and merge feed transaction
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
AWS_ACCESS_KEY_ID: ${{ secrets.COMPONENT_OBJECT_STORAGE_ACCESS_KEY }}
|
||||||
|
AWS_SECRET_ACCESS_KEY: ${{ secrets.COMPONENT_OBJECT_STORAGE_SECRET_KEY }}
|
||||||
|
AWS_DEFAULT_REGION: ${{ vars.COMPONENT_OBJECT_STORAGE_REGION }}
|
||||||
|
ECHOION_COMPONENT_SSH_KEY: ${{ secrets.RELEASE_CHECKOUT_SSH_KEY }}
|
||||||
|
ECHOION_DISTRIBUTION_BACKEND: ${{ vars.ECHOION_DISTRIBUTION_BACKEND }}
|
||||||
|
ECHOION_DISTRIBUTION_BASE_URL: ${{ vars.ECHOION_DISTRIBUTION_BASE_URL }}
|
||||||
|
ECHOION_FEED_BASE_URL: ${{ vars.ECHOION_FEED_BASE_URL }}
|
||||||
|
ECHOION_FEED_COMMIT_SIGNING_KEY: ${{ secrets.RELEASE_FEED_GIT_SIGNING_KEY }}
|
||||||
|
ECHOION_FEED_PRIVATE_KEY: ${{ secrets.RELEASE_FEED_ED25519_PRIVATE_KEY }}
|
||||||
|
ECHOION_FEED_REPOSITORY: ssh://gitea@git.faumaray.ru/Void/Echoion.git
|
||||||
|
ECHOION_FEED_SIGNING_KEY_ID: ${{ vars.ECHOION_FEED_SIGNING_KEY_ID }}
|
||||||
|
ECHOION_OBJECT_STORAGE_BUCKET: ${{ vars.COMPONENT_OBJECT_STORAGE_BUCKET }}
|
||||||
|
ECHOION_OBJECT_STORAGE_ENDPOINT: ${{ vars.COMPONENT_OBJECT_STORAGE_ENDPOINT }}
|
||||||
|
ECHOION_OBJECT_STORAGE_PREFIX: ${{ vars.COMPONENT_OBJECT_STORAGE_PREFIX }}
|
||||||
|
ECHOION_RELEASE_TAG_ALLOWED_SIGNERS: ${{ secrets.RELEASE_TAG_ALLOWED_SIGNERS }}
|
||||||
|
GITEA_API_URL: ${{ gitea.api_url }}
|
||||||
|
GITEA_EVENT_NAME: ${{ gitea.event_name }}
|
||||||
|
GITEA_REF_NAME: ${{ gitea.ref_name }}
|
||||||
|
GITEA_RUN_NUMBER: ${{ gitea.run_number }}
|
||||||
|
GITEA_SHA: ${{ gitea.sha }}
|
||||||
|
GITEA_REPOSITORY: ${{ gitea.repository }}
|
||||||
|
GITEA_RELEASE_TOKEN: ${{ secrets.RELEASE_BOT_TOKEN }}
|
||||||
|
RELEASE_TOOLS_REF: ${{ vars.ECHOION_RELEASE_TOOLS_REF }}
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
[[ "$RELEASE_TOOLS_REF" =~ ^[0-9a-f]{40}$ ]]
|
||||||
|
test "$(git -C .echoion-release-tools rev-parse HEAD)" = "$RELEASE_TOOLS_REF"
|
||||||
|
.echoion-release-tools/scripts/release-component.sh component.release.json
|
||||||
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
*build*
|
*build*
|
||||||
.cache
|
.cache
|
||||||
.idea
|
.idea
|
||||||
AGENTS.md
|
AGENTS.md
|
||||||
|
__pycache__/
|
||||||
+92
-5
@@ -1,5 +1,29 @@
|
|||||||
cmake_minimum_required(VERSION 4.0.0)
|
cmake_minimum_required(VERSION 4.0.0)
|
||||||
project(EchoionApi VERSION 1.0.0 LANGUAGES CXX)
|
if(NOT DEFINED ECHOION_PRODUCT_VERSION)
|
||||||
|
set(ECHOION_PRODUCT_VERSION 0.0.0)
|
||||||
|
endif()
|
||||||
|
if(NOT DEFINED ECHOION_COMPONENT_VERSION)
|
||||||
|
set(ECHOION_COMPONENT_VERSION "${ECHOION_PRODUCT_VERSION}")
|
||||||
|
endif()
|
||||||
|
project(EchoionApi VERSION "${ECHOION_COMPONENT_VERSION}" LANGUAGES CXX)
|
||||||
|
|
||||||
|
if(PROJECT_IS_TOP_LEVEL)
|
||||||
|
file(DOWNLOAD
|
||||||
|
https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.40.8/CPM.cmake
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake"
|
||||||
|
EXPECTED_HASH
|
||||||
|
SHA256=78ba32abdf798bc616bab7c73aac32a17bbd7b06ad9e26a6add69de8f3ae4791)
|
||||||
|
include("${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake")
|
||||||
|
CPMAddPackage(
|
||||||
|
NAME Void
|
||||||
|
GIT_REPOSITORY ssh://gitea@git.faumaray.ru/void/voidlibrary.git
|
||||||
|
GIT_TAG main
|
||||||
|
OPTIONS "VOID_ENABLE_TESTING OFF")
|
||||||
|
option(BUILD_TESTS "Build component tests" ON)
|
||||||
|
if(BUILD_TESTS)
|
||||||
|
enable_testing()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
set(CMAKE_CXX_STANDARD 26)
|
set(CMAKE_CXX_STANDARD 26)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
@@ -7,6 +31,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
|
|||||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||||
|
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
|
find_package(Boost 1.87 CONFIG REQUIRED)
|
||||||
|
|
||||||
# ===== Granular API Libraries =====
|
# ===== Granular API Libraries =====
|
||||||
# Directory structure:
|
# Directory structure:
|
||||||
@@ -72,7 +97,49 @@ target_include_directories(EchoionApiPlugin INTERFACE
|
|||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/echoion/api/plugin>
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/echoion/api/plugin>
|
||||||
$<INSTALL_INTERFACE:include/echoion/api/plugin>
|
$<INSTALL_INTERFACE:include/echoion/api/plugin>
|
||||||
)
|
)
|
||||||
target_link_libraries(EchoionApiPlugin INTERFACE Echoion::ApiBase)
|
target_link_libraries(EchoionApiPlugin INTERFACE
|
||||||
|
Echoion::ApiBase
|
||||||
|
Echoion::ApiTrack
|
||||||
|
Void::Plugin
|
||||||
|
)
|
||||||
|
|
||||||
|
# Shared first-party plugin configuration and URL-host safety helpers. Their
|
||||||
|
# implementation remains in the SDK so independently built plugins do not
|
||||||
|
# duplicate or diverge from the same validation rules.
|
||||||
|
add_library(EchoionApiPluginSdk STATIC
|
||||||
|
src/ShortUrlSupport.cpp
|
||||||
|
)
|
||||||
|
add_library(Echoion::ApiPluginSdk ALIAS EchoionApiPluginSdk)
|
||||||
|
set_target_properties(EchoionApiPluginSdk PROPERTIES
|
||||||
|
EXPORT_NAME ApiPluginSdk
|
||||||
|
POSITION_INDEPENDENT_CODE ON
|
||||||
|
)
|
||||||
|
target_compile_features(EchoionApiPluginSdk PUBLIC cxx_std_26)
|
||||||
|
target_include_directories(EchoionApiPluginSdk PUBLIC
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
|
$<INSTALL_INTERFACE:include>
|
||||||
|
)
|
||||||
|
target_link_libraries(EchoionApiPluginSdk
|
||||||
|
PUBLIC
|
||||||
|
Echoion::ApiPlugin
|
||||||
|
Void::Data
|
||||||
|
Void::Net
|
||||||
|
Void::Text
|
||||||
|
)
|
||||||
|
target_include_directories(EchoionApiPluginSdk PRIVATE ${Boost_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
# Echoion's discovery symbol and SDK aliases for VoidLibrary's reusable C++
|
||||||
|
# module descriptor, lifecycle, SemVer, JSON, Result, and service types.
|
||||||
|
add_library(EchoionApiModuleAbi INTERFACE)
|
||||||
|
add_library(Echoion::ApiModuleAbi ALIAS EchoionApiModuleAbi)
|
||||||
|
set_target_properties(EchoionApiModuleAbi PROPERTIES
|
||||||
|
EXPORT_NAME ApiModuleAbi
|
||||||
|
)
|
||||||
|
target_include_directories(EchoionApiModuleAbi INTERFACE
|
||||||
|
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||||
|
$<INSTALL_INTERFACE:include>
|
||||||
|
)
|
||||||
|
target_link_libraries(EchoionApiModuleAbi INTERFACE Void::Plugin)
|
||||||
|
|
||||||
# 6. Config Types (depends on Network, Audio)
|
# 6. Config Types (depends on Network, Audio)
|
||||||
add_library(EchoionApiConfig INTERFACE)
|
add_library(EchoionApiConfig INTERFACE)
|
||||||
@@ -163,7 +230,7 @@ target_include_directories(EchoionApiOpaque INTERFACE
|
|||||||
)
|
)
|
||||||
target_link_libraries(EchoionApiOpaque INTERFACE Echoion::ApiBase)
|
target_link_libraries(EchoionApiOpaque INTERFACE Echoion::ApiBase)
|
||||||
|
|
||||||
# 12a. PluginInterface only (minimal - for Plugin to implement)
|
# 12a. Host interface used by Core and EchoionStandalone
|
||||||
add_library(EchoionApiPluginInterface INTERFACE)
|
add_library(EchoionApiPluginInterface INTERFACE)
|
||||||
add_library(Echoion::ApiPluginInterface ALIAS EchoionApiPluginInterface)
|
add_library(Echoion::ApiPluginInterface ALIAS EchoionApiPluginInterface)
|
||||||
target_include_directories(EchoionApiPluginInterface INTERFACE
|
target_include_directories(EchoionApiPluginInterface INTERFACE
|
||||||
@@ -180,7 +247,7 @@ target_link_libraries(EchoionApiPluginInterface INTERFACE
|
|||||||
Echoion::ApiOpaque
|
Echoion::ApiOpaque
|
||||||
)
|
)
|
||||||
|
|
||||||
# 12b. CoreInterface (decoupled - for Plugin to call Core)
|
# 12b. CoreInterface (decoupled host boundary)
|
||||||
add_library(EchoionApiCoreInterface INTERFACE)
|
add_library(EchoionApiCoreInterface INTERFACE)
|
||||||
add_library(Echoion::ApiCoreInterface ALIAS EchoionApiCoreInterface)
|
add_library(Echoion::ApiCoreInterface ALIAS EchoionApiCoreInterface)
|
||||||
target_include_directories(EchoionApiCoreInterface INTERFACE
|
target_include_directories(EchoionApiCoreInterface INTERFACE
|
||||||
@@ -194,7 +261,7 @@ target_link_libraries(EchoionApiCoreInterface INTERFACE
|
|||||||
Echoion::ApiOpaque
|
Echoion::ApiOpaque
|
||||||
)
|
)
|
||||||
|
|
||||||
# 12c. Legacy Interfaces (both)
|
# 12c. Combined host interfaces
|
||||||
add_library(EchoionApiInterfaces INTERFACE)
|
add_library(EchoionApiInterfaces INTERFACE)
|
||||||
add_library(Echoion::ApiInterfaces ALIAS EchoionApiInterfaces)
|
add_library(Echoion::ApiInterfaces ALIAS EchoionApiInterfaces)
|
||||||
target_link_libraries(EchoionApiInterfaces INTERFACE
|
target_link_libraries(EchoionApiInterfaces INTERFACE
|
||||||
@@ -220,6 +287,8 @@ target_include_directories(EchoionApi INTERFACE
|
|||||||
$<INSTALL_INTERFACE:include/echoion/api>
|
$<INSTALL_INTERFACE:include/echoion/api>
|
||||||
)
|
)
|
||||||
target_link_libraries(EchoionApi INTERFACE
|
target_link_libraries(EchoionApi INTERFACE
|
||||||
|
Echoion::ApiModuleAbi
|
||||||
|
Echoion::ApiPluginSdk
|
||||||
Echoion::ApiBase
|
Echoion::ApiBase
|
||||||
Echoion::ApiAudio
|
Echoion::ApiAudio
|
||||||
Echoion::ApiTrack
|
Echoion::ApiTrack
|
||||||
@@ -246,6 +315,8 @@ endif()
|
|||||||
|
|
||||||
# Install and export all modules
|
# Install and export all modules
|
||||||
install(TARGETS
|
install(TARGETS
|
||||||
|
EchoionApiModuleAbi
|
||||||
|
EchoionApiPluginSdk
|
||||||
EchoionApiBase
|
EchoionApiBase
|
||||||
EchoionApiAudio
|
EchoionApiAudio
|
||||||
EchoionApiTrack
|
EchoionApiTrack
|
||||||
@@ -267,6 +338,10 @@ install(TARGETS
|
|||||||
INCLUDES DESTINATION include
|
INCLUDES DESTINATION include
|
||||||
)
|
)
|
||||||
|
|
||||||
|
install(DIRECTORY include/ DESTINATION include)
|
||||||
|
install(FILES abi/echoion-module-v1.json
|
||||||
|
DESTINATION share/echoion/abi)
|
||||||
|
|
||||||
install(EXPORT EchoionApiTargets
|
install(EXPORT EchoionApiTargets
|
||||||
FILE EchoionApiTargets.cmake
|
FILE EchoionApiTargets.cmake
|
||||||
NAMESPACE Echoion::
|
NAMESPACE Echoion::
|
||||||
@@ -290,3 +365,15 @@ install(FILES
|
|||||||
"${CMAKE_CURRENT_BINARY_DIR}/EchoionApiConfigVersion.cmake"
|
"${CMAKE_CURRENT_BINARY_DIR}/EchoionApiConfigVersion.cmake"
|
||||||
DESTINATION lib/cmake/EchoionApi
|
DESTINATION lib/cmake/EchoionApi
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(BUILD_TESTS)
|
||||||
|
find_package(Python3 QUIET COMPONENTS Interpreter)
|
||||||
|
if(Python3_Interpreter_FOUND)
|
||||||
|
add_test(NAME echoion_module_abi_contract_tests
|
||||||
|
COMMAND "${Python3_EXECUTABLE}"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/tests/test_abi_contract.py")
|
||||||
|
add_test(NAME echoion_module_abi_c_header_tests
|
||||||
|
COMMAND "${Python3_EXECUTABLE}"
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/tests/test_module_abi_c.py")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
+5
-4
@@ -69,7 +69,7 @@ EchoionApi/include/echoion/api/
|
|||||||
|
|
||||||
## Include Path Changes
|
## Include Path Changes
|
||||||
|
|
||||||
### For Plugin (minimal):
|
### For a host adapter (minimal):
|
||||||
|
|
||||||
**Before:**
|
**Before:**
|
||||||
```cpp
|
```cpp
|
||||||
@@ -83,7 +83,8 @@ EchoionApi/include/echoion/api/
|
|||||||
#include <CoreInterface.hpp>
|
#include <CoreInterface.hpp>
|
||||||
```
|
```
|
||||||
|
|
||||||
The CMake target `Echoion::ApiPlugin` will add the correct include paths.
|
The CMake target `Echoion::ApiPlugin` provides the event and host DTO include
|
||||||
|
paths retained for source compatibility.
|
||||||
|
|
||||||
### For Core:
|
### For Core:
|
||||||
|
|
||||||
@@ -101,9 +102,9 @@ The CMake target `Echoion::ApiEventBus` adds `eventbus/` to the include path.
|
|||||||
|
|
||||||
## CMake Usage
|
## CMake Usage
|
||||||
|
|
||||||
### Plugin only needs:
|
### Standalone host needs:
|
||||||
```cmake
|
```cmake
|
||||||
target_link_libraries(EchoionPlugin PRIVATE
|
target_link_libraries(EchoionStandalone PRIVATE
|
||||||
Echoion::ApiBase
|
Echoion::ApiBase
|
||||||
Echoion::ApiPlugin
|
Echoion::ApiPlugin
|
||||||
Echoion::ApiInterfaces
|
Echoion::ApiInterfaces
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
{
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"contractId": "echoion.module",
|
||||||
|
"language": "C",
|
||||||
|
"header": "echoion/api/module/ModuleAbi.h",
|
||||||
|
"querySymbol": "echoion_module_abi_query",
|
||||||
|
"entryPoints": [
|
||||||
|
{
|
||||||
|
"name": "echoion_module_abi_query",
|
||||||
|
"returns": "const echoion_module_descriptor_v1*",
|
||||||
|
"ownership": "static-borrowed"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"name": "echoion_module_descriptor_v1",
|
||||||
|
"version": 1,
|
||||||
|
"sizeVersioned": true,
|
||||||
|
"fields": [
|
||||||
|
{"name": "struct_size", "type": "size_t"},
|
||||||
|
{"name": "abi_version", "type": "uint32_t"},
|
||||||
|
{"name": "component_id", "type": "echoion_string_view_v1"},
|
||||||
|
{"name": "version_major", "type": "uint32_t"},
|
||||||
|
{"name": "version_minor", "type": "uint32_t"},
|
||||||
|
{"name": "version_patch", "type": "uint32_t"},
|
||||||
|
{"name": "version_prerelease", "type": "echoion_string_view_v1"},
|
||||||
|
{"name": "abi_hash", "type": "echoion_string_view_v1"},
|
||||||
|
{"name": "dependencies", "type": "const echoion_module_dependency_v1*"},
|
||||||
|
{"name": "dependency_count", "type": "size_t"},
|
||||||
|
{"name": "activation_policy", "type": "echoion_activation_policy_v1"},
|
||||||
|
{"name": "api", "type": "const echoion_module_api_v1*"},
|
||||||
|
{"name": "reserved", "type": "const void*[8]"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "echoion_module_api_v1",
|
||||||
|
"version": 1,
|
||||||
|
"sizeVersioned": true,
|
||||||
|
"fields": [
|
||||||
|
{"name": "struct_size", "type": "size_t"},
|
||||||
|
{"name": "abi_version", "type": "uint32_t"},
|
||||||
|
{"name": "create", "type": "echoion_status_v1 (*)(const echoion_module_host_v1*, echoion_module_instance_v1*)"},
|
||||||
|
{"name": "destroy", "type": "void (*)(echoion_module_instance_v1)"},
|
||||||
|
{"name": "activate", "type": "echoion_status_v1 (*)(echoion_module_instance_v1)"},
|
||||||
|
{"name": "quiesce", "type": "echoion_status_v1 (*)(echoion_module_instance_v1, int64_t)"},
|
||||||
|
{"name": "checkpoint", "type": "echoion_status_v1 (*)(echoion_module_instance_v1, echoion_write_bytes_fn_v1, void*)"},
|
||||||
|
{"name": "restore", "type": "echoion_status_v1 (*)(echoion_module_instance_v1, echoion_bytes_view_v1)"},
|
||||||
|
{"name": "readiness", "type": "echoion_status_v1 (*)(echoion_module_instance_v1, echoion_module_readiness_v1*)"},
|
||||||
|
{"name": "deactivate", "type": "echoion_status_v1 (*)(echoion_module_instance_v1)"}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "echoion_module_host_v1",
|
||||||
|
"version": 1,
|
||||||
|
"sizeVersioned": true,
|
||||||
|
"fields": [
|
||||||
|
{"name": "struct_size", "type": "size_t"},
|
||||||
|
{"name": "abi_version", "type": "uint32_t"},
|
||||||
|
{"name": "context", "type": "void*"},
|
||||||
|
{"name": "query_service", "type": "echoion_query_service_fn_v1"},
|
||||||
|
{"name": "log", "type": "echoion_log_fn_v1"}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"rules": {
|
||||||
|
"opaqueHandles": true,
|
||||||
|
"explicitOwnership": true,
|
||||||
|
"exceptionsCrossBoundary": false,
|
||||||
|
"cppTypesCrossBoundary": false,
|
||||||
|
"appendOnlyCompatibility": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"schemaVersion": 1,
|
||||||
|
"componentId": "EchoionApi",
|
||||||
|
"productCompatibility": ">=2.0.0 <3.0.0",
|
||||||
|
"publishNightly": true,
|
||||||
|
"cmakeOptions": {}
|
||||||
|
}
|
||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "api/network/NetworkInterface.hpp"
|
#include "api/network/NetworkInterface.hpp"
|
||||||
#include "api/network/NetworkTypes.hpp"
|
#include "api/network/NetworkTypes.hpp"
|
||||||
#include "api/plugin/PluginTypes.hpp"
|
#include "api/plugin/PluginTypes.hpp"
|
||||||
|
#include "api/plugin/ExtensionPlugin.hpp"
|
||||||
#include "api/rpc/RpcTypes.hpp"
|
#include "api/rpc/RpcTypes.hpp"
|
||||||
#include "api/track/TrackTypes.hpp"
|
#include "api/track/TrackTypes.hpp"
|
||||||
#include "api/youtube/YouTubeTypes.hpp"
|
#include "api/youtube/YouTubeTypes.hpp"
|
||||||
|
|||||||
@@ -16,9 +16,9 @@ namespace Echoion::Api
|
|||||||
|
|
||||||
// Version constants
|
// Version constants
|
||||||
inline constexpr uint32_t VERSION_MAJOR = 1;
|
inline constexpr uint32_t VERSION_MAJOR = 1;
|
||||||
inline constexpr uint32_t VERSION_MINOR = 0;
|
inline constexpr uint32_t VERSION_MINOR = 1;
|
||||||
inline constexpr uint32_t VERSION_PATCH = 0;
|
inline constexpr uint32_t VERSION_PATCH = 1;
|
||||||
inline constexpr const char* VERSION_STRING = "1.0.0";
|
inline constexpr const char* VERSION_STRING = "1.1.1";
|
||||||
|
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifndef PLUGIN
|
|
||||||
#include "ConfigTypes.hpp"
|
#include "ConfigTypes.hpp"
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
@@ -48,6 +47,7 @@ namespace Echoion::Api
|
|||||||
[[nodiscard]] const BotConfig& getBot() const;
|
[[nodiscard]] const BotConfig& getBot() const;
|
||||||
[[nodiscard]] const YouTubeConfig& getYouTube() const;
|
[[nodiscard]] const YouTubeConfig& getYouTube() const;
|
||||||
[[nodiscard]] const NetworkConfig& getNetwork() const;
|
[[nodiscard]] const NetworkConfig& getNetwork() const;
|
||||||
|
[[nodiscard]] const SourcesConfig& getSources() const;
|
||||||
[[nodiscard]] const TeamSpeakConfig& getTeamSpeak() const;
|
[[nodiscard]] const TeamSpeakConfig& getTeamSpeak() const;
|
||||||
[[nodiscard]] const SecurityConfig& getSecurity() const;
|
[[nodiscard]] const SecurityConfig& getSecurity() const;
|
||||||
[[nodiscard]] const FeaturesConfig& getFeatures() const;
|
[[nodiscard]] const FeaturesConfig& getFeatures() const;
|
||||||
@@ -92,5 +92,3 @@ namespace Echoion::Api
|
|||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Echoion::Api
|
} // namespace Echoion::Api
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifndef PLUGIN
|
|
||||||
#include "AudioTypes.hpp"
|
#include "AudioTypes.hpp"
|
||||||
#include "NetworkTypes.hpp"
|
#include "NetworkTypes.hpp"
|
||||||
#include "Types.hpp"
|
#include "Types.hpp"
|
||||||
@@ -29,19 +28,17 @@ namespace Echoion::Api
|
|||||||
struct BotConfig {
|
struct BotConfig {
|
||||||
std::string botName = "Echoion";
|
std::string botName = "Echoion";
|
||||||
std::string commandPrefix = "!";
|
std::string commandPrefix = "!";
|
||||||
|
// Default bot language ("en" or "ru"). Applies to users who have
|
||||||
|
// not picked a per-user language. Anything else normalises to "en".
|
||||||
|
std::string language = "en";
|
||||||
float defaultVolume = 0.5f;
|
float defaultVolume = 0.5f;
|
||||||
uint32_t maxQueueSize = 100;
|
uint32_t maxQueueSize = 100;
|
||||||
|
// How long the playback engine waits (emitting silence) for a
|
||||||
|
// late stream resolve before skipping the track.
|
||||||
std::chrono::milliseconds trackTimeout =
|
std::chrono::milliseconds trackTimeout =
|
||||||
std::chrono::milliseconds(30000);
|
std::chrono::milliseconds(10000);
|
||||||
|
// Crossfade between tracks; 0 = plain gapless handoff.
|
||||||
// Reconnection settings
|
std::chrono::milliseconds crossfade = std::chrono::milliseconds(0);
|
||||||
bool autoReconnect = true;
|
|
||||||
std::chrono::milliseconds reconnectDelay =
|
|
||||||
std::chrono::milliseconds(5000);
|
|
||||||
uint32_t maxReconnectAttempts = 5;
|
|
||||||
|
|
||||||
// Audio quality settings
|
|
||||||
AudioQuality preferredQuality = AudioQuality::High;
|
|
||||||
bool allowPlaylistImports = true;
|
bool allowPlaylistImports = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -63,6 +60,73 @@ namespace Echoion::Api
|
|||||||
std::string rpcBindAddress = "127.0.0.1";
|
std::string rpcBindAddress = "127.0.0.1";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Browser web interface (EchoionWeb). Serves the public dashboard and
|
||||||
|
// same-origin RPC bridge. Watch Together is deployed independently and
|
||||||
|
// linked through watchUrl.
|
||||||
|
struct WebConfig {
|
||||||
|
bool enabled = false;
|
||||||
|
uint16_t port = 8080;
|
||||||
|
std::string bindAddress = "127.0.0.1";
|
||||||
|
std::string webRoot = "./web";
|
||||||
|
// Explicit RPC WebSocket URL the browser should use. When empty the
|
||||||
|
// UI derives ws://<page-host>:<rpcPort> from the served config.
|
||||||
|
std::string rpcUrl;
|
||||||
|
// Public address users reach the web interface at (e.g.
|
||||||
|
// "https://bot.example.com"). Required by the internal URL
|
||||||
|
// shortener and also used by !help when set; serving is unaffected.
|
||||||
|
std::string publicUrl;
|
||||||
|
// External VoidWatch deployment. Echoion only presents this link
|
||||||
|
// and redirects the retired local /watch entrypoint to it.
|
||||||
|
std::string watchUrl;
|
||||||
|
// Allow the Now Playing view to show the current song's video
|
||||||
|
// (muted, synced). Users can still disable it locally; this is
|
||||||
|
// the server-wide off switch, surfaced through /config.json.
|
||||||
|
bool nowPlayingVideo = true;
|
||||||
|
// Forwarded client addresses are trusted only when the immediate
|
||||||
|
// peer belongs to one of these IPv4/IPv6 CIDRs. Empty is safest and
|
||||||
|
// ignores X-Forwarded-For entirely.
|
||||||
|
std::vector<std::string> trustedProxyCidrs;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UrlShorteningConfig {
|
||||||
|
bool enabled = false;
|
||||||
|
std::string provider = "url-shortener-internal";
|
||||||
|
std::vector<std::string> sources = {"youtube"};
|
||||||
|
std::chrono::milliseconds timeout = std::chrono::milliseconds(3000);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PluginsConfig {
|
||||||
|
// Empty resolves to a plugins.d directory beside the main config.
|
||||||
|
std::string configDirectory;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Music source resolution chain. Default order tries the native
|
||||||
|
// innertube YouTube path and Yandex Music first, then falls back to
|
||||||
|
// (optionally proxied) yt-dlp last.
|
||||||
|
struct SourcesConfig {
|
||||||
|
std::vector<std::string> order = {"innertube", "yandex",
|
||||||
|
"direct-url", "ytdlp-direct",
|
||||||
|
"ytdlp-proxied"};
|
||||||
|
// How long a failing source is skipped before being retried.
|
||||||
|
std::chrono::milliseconds failureCooldown =
|
||||||
|
std::chrono::milliseconds(300000); // 5m
|
||||||
|
// Hedged stream resolution: when the first source hasn't
|
||||||
|
// answered within this delay, the second candidate races it
|
||||||
|
// (first success wins). 0 disables hedging.
|
||||||
|
std::chrono::milliseconds hedgeDelay =
|
||||||
|
std::chrono::milliseconds(300);
|
||||||
|
// Native innertube player API (fastest YouTube path; one HTTP
|
||||||
|
// POST). youtubei is geo-blocked without a proxy, so with
|
||||||
|
// requireProxy the source is skipped when none is configured.
|
||||||
|
bool innertubeEnabled = true;
|
||||||
|
bool innertubeRequireProxy = true;
|
||||||
|
// Native Yandex Music (unofficial API). Full tracks require an
|
||||||
|
// OAuth token from an account with Plus; without one, yandex
|
||||||
|
// URLs fall back to ytdlp-direct.
|
||||||
|
bool yandexEnabled = true;
|
||||||
|
std::optional<std::string> yandexToken;
|
||||||
|
};
|
||||||
|
|
||||||
// TeamSpeak Server Connection
|
// TeamSpeak Server Connection
|
||||||
struct TeamSpeakConfig {
|
struct TeamSpeakConfig {
|
||||||
std::string address = "localhost";
|
std::string address = "localhost";
|
||||||
@@ -86,6 +150,9 @@ namespace Echoion::Api
|
|||||||
std::chrono::milliseconds(3600000);
|
std::chrono::milliseconds(3600000);
|
||||||
bool enableAuditLog = true;
|
bool enableAuditLog = true;
|
||||||
std::optional<std::string> apiKey;
|
std::optional<std::string> apiKey;
|
||||||
|
// Reserved, not currently honored: the web UI and /rpc bridge are
|
||||||
|
// same-origin behind the web server, so no CORS headers are
|
||||||
|
// emitted.
|
||||||
bool allowCors = false;
|
bool allowCors = false;
|
||||||
std::vector<std::string> corsOrigins;
|
std::vector<std::string> corsOrigins;
|
||||||
};
|
};
|
||||||
@@ -100,33 +167,122 @@ namespace Echoion::Api
|
|||||||
bool autoStartOnSubscribe = true;
|
bool autoStartOnSubscribe = true;
|
||||||
bool pauseOnEmptySubscribers = true;
|
bool pauseOnEmptySubscribers = true;
|
||||||
bool resumeOnSubscriberReturn = true;
|
bool resumeOnSubscriberReturn = true;
|
||||||
|
// Radio mode: when the queue runs dry, enqueue tracks related to
|
||||||
|
// the last played one (via Invidious recommendations).
|
||||||
|
bool autoplay = false;
|
||||||
|
|
||||||
// Queue management
|
// Loudness normalization: slow AGC toward the target RMS level
|
||||||
std::string shuffleMode = "random";
|
// so quiet and loud tracks play back at a similar volume.
|
||||||
|
bool normalizeLoudness = false;
|
||||||
|
float targetLoudnessDb = -14.0f;
|
||||||
|
|
||||||
|
// Queue management: initial state on cold start ("off"/"random",
|
||||||
|
// "off"/"all"). Runtime toggles are not written back.
|
||||||
|
std::string shuffleMode = "off";
|
||||||
std::string repeatMode = "off";
|
std::string repeatMode = "off";
|
||||||
uint32_t maxHistorySize = 50;
|
uint32_t maxHistorySize = 50;
|
||||||
|
|
||||||
|
// Vote-to-skip: votes needed to skip the current track.
|
||||||
|
// 0 = majority of online subscribers.
|
||||||
|
uint32_t voteSkipThreshold = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Advanced Settings
|
// Advanced Settings
|
||||||
struct AdvancedConfig {
|
struct AdvancedConfig {
|
||||||
// Audio configuration
|
// Local audio track cache (downloaded/streamed files reused
|
||||||
uint32_t sampleRate = 192000;
|
// across plays and restarts).
|
||||||
uint32_t channels = 2;
|
|
||||||
uint32_t bufferSize = 7680;
|
|
||||||
|
|
||||||
// Thread pool configuration
|
|
||||||
uint32_t commandThreadPoolSize = 4;
|
|
||||||
uint32_t networkThreadPoolSize = 4;
|
|
||||||
uint32_t decoderThreads = 2;
|
|
||||||
|
|
||||||
// Cache settings
|
|
||||||
bool cacheEnabled = true;
|
bool cacheEnabled = true;
|
||||||
std::string cacheMaxSize = "1GB";
|
std::string cacheMaxSize = "1GB";
|
||||||
uint32_t cacheTTL = 86400;
|
uint32_t cacheTTL = 86400; // seconds
|
||||||
uint32_t tempCleanupInterval = 3600;
|
uint32_t tempCleanupInterval = 3600; // seconds
|
||||||
};
|
};
|
||||||
|
|
||||||
// ServerConfig for Plugin interface (mirrors PluginTypes.hpp version)
|
// Process logging. The active file is always archived at process startup,
|
||||||
|
// then rotated by size while the bot is running.
|
||||||
|
struct LoggingConfig {
|
||||||
|
bool console = true;
|
||||||
|
std::string level = "debug";
|
||||||
|
std::string fileName = "echoion.log";
|
||||||
|
uint64_t maxFileSizeBytes = 10 * 1024 * 1024;
|
||||||
|
uint32_t maxFiles = 10;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Component updater. Runtime means the complete relocatable daemon bundle,
|
||||||
|
// not only the echoiond ELF. Core and managed extension plugins may use
|
||||||
|
// independent channels, but the updater still enforces the compatibility
|
||||||
|
// metadata carried by the selected feed releases.
|
||||||
|
struct UpdatePublicKey {
|
||||||
|
std::string id;
|
||||||
|
std::string ed25519;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UpdateSourceConfig {
|
||||||
|
// "direct" addresses one feed document. "component-layout"
|
||||||
|
// addresses a channel root containing catalog.json and component
|
||||||
|
// discovery documents.
|
||||||
|
std::string kind = "direct";
|
||||||
|
// Empty is only meaningful for the built-in "official" source and
|
||||||
|
// resolves to the URL injected by the release build.
|
||||||
|
std::string url;
|
||||||
|
std::vector<UpdatePublicKey> publicKeys;
|
||||||
|
bool allowUnsigned = false;
|
||||||
|
// Environment variable name only. Secret values are never
|
||||||
|
// persisted.
|
||||||
|
std::string bearerTokenEnv;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UpdateComponentConfig {
|
||||||
|
bool enabled = true;
|
||||||
|
std::string source = "official";
|
||||||
|
std::string channel = "stable";
|
||||||
|
bool autoApply = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PluginUpdateOverride {
|
||||||
|
std::string source = "official";
|
||||||
|
std::string channel = "stable";
|
||||||
|
bool autoApply = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct PluginUpdatesConfig {
|
||||||
|
bool enabled = true;
|
||||||
|
std::string source = "official";
|
||||||
|
std::string channel = "stable";
|
||||||
|
bool autoApply = true;
|
||||||
|
bool managedOnly = true;
|
||||||
|
std::map<std::string, PluginUpdateOverride> overrides;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UpdateMaintenanceWindow {
|
||||||
|
// HH:MM in UTC. The updater validates the value before saving it.
|
||||||
|
std::string start = "03:00";
|
||||||
|
std::chrono::milliseconds duration = std::chrono::hours(2);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct UpdatesConfig {
|
||||||
|
bool enabled = true;
|
||||||
|
std::chrono::milliseconds checkInterval = std::chrono::hours(6);
|
||||||
|
std::chrono::milliseconds jitter = std::chrono::minutes(30);
|
||||||
|
UpdateMaintenanceWindow maintenanceWindowUtc;
|
||||||
|
std::chrono::milliseconds maxRuntimeDeferral =
|
||||||
|
std::chrono::hours(24);
|
||||||
|
// Number of previous healthy versions retained in addition to
|
||||||
|
// active.
|
||||||
|
uint32_t retainHealthyVersions = 2;
|
||||||
|
std::map<std::string, UpdateSourceConfig> sources = {{
|
||||||
|
"official",
|
||||||
|
UpdateSourceConfig{.kind = "component-layout",
|
||||||
|
.url = {},
|
||||||
|
.publicKeys = {},
|
||||||
|
.allowUnsigned = false,
|
||||||
|
.bearerTokenEnv = {}},
|
||||||
|
}};
|
||||||
|
UpdateComponentConfig runtime;
|
||||||
|
UpdateComponentConfig core;
|
||||||
|
PluginUpdatesConfig plugins;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Connection settings passed across the Echoion host interface.
|
||||||
struct ServerConfig {
|
struct ServerConfig {
|
||||||
std::string address;
|
std::string address;
|
||||||
uint16_t port = 0;
|
uint16_t port = 0;
|
||||||
@@ -153,13 +309,18 @@ namespace Echoion::Api
|
|||||||
BotConfig bot;
|
BotConfig bot;
|
||||||
YouTubeConfig youtube;
|
YouTubeConfig youtube;
|
||||||
NetworkConfig network;
|
NetworkConfig network;
|
||||||
|
SourcesConfig sources;
|
||||||
TeamSpeakConfig teamspeak;
|
TeamSpeakConfig teamspeak;
|
||||||
SecurityConfig security;
|
SecurityConfig security;
|
||||||
FeaturesConfig features;
|
FeaturesConfig features;
|
||||||
AdvancedConfig advanced;
|
AdvancedConfig advanced;
|
||||||
|
LoggingConfig logging;
|
||||||
|
UpdatesConfig updates;
|
||||||
|
UrlShorteningConfig urlShortening;
|
||||||
|
PluginsConfig plugins;
|
||||||
AdminCredentials admin;
|
AdminCredentials admin;
|
||||||
|
WebConfig web;
|
||||||
std::map<std::string, ConfigEntry> custom;
|
std::map<std::string, ConfigEntry> custom;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Echoion::Api
|
} // namespace Echoion::Api
|
||||||
#endif
|
|
||||||
@@ -64,6 +64,27 @@ namespace Echoion::Api
|
|||||||
uint64_t mostPlayedCount = 0;
|
uint64_t mostPlayedCount = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Server-wide aggregate statistics (web dashboard)
|
||||||
|
struct AggregateStats {
|
||||||
|
uint64_t tracksToday = 0; // completed plays today
|
||||||
|
uint64_t listeningMsToday = 0; // summed play duration today
|
||||||
|
uint64_t queueAdditionsToday = 0;
|
||||||
|
uint64_t skipsToday = 0;
|
||||||
|
uint64_t playsTotal = 0;
|
||||||
|
uint64_t skipsTotal = 0;
|
||||||
|
// Most active requesters, most additions first.
|
||||||
|
struct TopRequester {
|
||||||
|
std::string uid; // TeamSpeak uid (may be empty for old rows)
|
||||||
|
std::string nickname;
|
||||||
|
uint64_t count = 0;
|
||||||
|
};
|
||||||
|
std::vector<TopRequester> topRequesters;
|
||||||
|
// Source split over the whole history
|
||||||
|
uint64_t youtubeCount = 0;
|
||||||
|
uint64_t yandexCount = 0;
|
||||||
|
uint64_t otherCount = 0;
|
||||||
|
};
|
||||||
|
|
||||||
// Main database interface
|
// Main database interface
|
||||||
class Database
|
class Database
|
||||||
{
|
{
|
||||||
@@ -112,6 +133,10 @@ namespace Echoion::Api
|
|||||||
[[nodiscard]] Api::Result<std::vector<Playlist>>
|
[[nodiscard]] Api::Result<std::vector<Playlist>>
|
||||||
getUserPlaylists(uint64_t userId);
|
getUserPlaylists(uint64_t userId);
|
||||||
|
|
||||||
|
// Get every playlist (used by the RPC GetPlaylists endpoint).
|
||||||
|
[[nodiscard]] Api::Result<std::vector<Playlist>>
|
||||||
|
getAllPlaylists();
|
||||||
|
|
||||||
// Update playlist
|
// Update playlist
|
||||||
Api::Result<void> updatePlaylist(
|
Api::Result<void> updatePlaylist(
|
||||||
uint64_t id,
|
uint64_t id,
|
||||||
@@ -154,6 +179,14 @@ namespace Echoion::Api
|
|||||||
[[nodiscard]] Api::Result<std::vector<TrackInfo>>
|
[[nodiscard]] Api::Result<std::vector<TrackInfo>>
|
||||||
getRecentlyPlayed(uint64_t userId, size_t limit = 20);
|
getRecentlyPlayed(uint64_t userId, size_t limit = 20);
|
||||||
|
|
||||||
|
// Record a skipped track (playback aborted by user action)
|
||||||
|
Api::Result<void> recordSkip(const TrackInfo& track,
|
||||||
|
uint64_t playedBy);
|
||||||
|
|
||||||
|
// Log a queue addition (daily stats / top requesters)
|
||||||
|
Api::Result<void> logQueueAddition(const std::string& uid,
|
||||||
|
const std::string& nickname);
|
||||||
|
|
||||||
// ===== Favorites =====
|
// ===== Favorites =====
|
||||||
|
|
||||||
// Add track to favorites
|
// Add track to favorites
|
||||||
@@ -185,6 +218,44 @@ namespace Echoion::Api
|
|||||||
std::vector<std::pair<TrackInfo, uint64_t>>>
|
std::vector<std::pair<TrackInfo, uint64_t>>>
|
||||||
getMostPlayed(uint64_t userId, size_t limit = 10);
|
getMostPlayed(uint64_t userId, size_t limit = 10);
|
||||||
|
|
||||||
|
// Get server-wide aggregate statistics (web dashboard)
|
||||||
|
[[nodiscard]] Api::Result<AggregateStats> getAggregateStats();
|
||||||
|
|
||||||
|
// ===== Key/value store =====
|
||||||
|
// Small persisted state (healthy instance lists, ...). Values
|
||||||
|
// are opaque strings (callers serialize as needed).
|
||||||
|
[[nodiscard]] Api::Result<std::optional<std::string>>
|
||||||
|
getKv(const std::string& key);
|
||||||
|
Api::Result<void> setKv(const std::string& key,
|
||||||
|
const std::string& value);
|
||||||
|
|
||||||
|
// ===== Cached avatars (web UI) =====
|
||||||
|
// TeamSpeak avatar images persisted by uid so the web UI can show
|
||||||
|
// them even when the client is offline or out of the bot's view
|
||||||
|
// (the live TS avatar cache only holds in-view clients). `data` is
|
||||||
|
// base64-encoded image bytes.
|
||||||
|
struct CachedAvatar {
|
||||||
|
std::string uid;
|
||||||
|
std::string mime;
|
||||||
|
std::string dataBase64;
|
||||||
|
// The source myTeamSpeak avatar URL, so an offline user's
|
||||||
|
// avatar can be re-fetched even when the image bytes were
|
||||||
|
// never stored. Empty for legacy/file avatars.
|
||||||
|
std::string url;
|
||||||
|
};
|
||||||
|
// Image (mime + base64 data + url) for one uid, or nullopt if none.
|
||||||
|
[[nodiscard]] Api::Result<std::optional<CachedAvatar>>
|
||||||
|
getCachedAvatar(const std::string& uid);
|
||||||
|
// Insert or replace the cached avatar image for a uid (keeps any
|
||||||
|
// previously stored url).
|
||||||
|
Api::Result<void> putCachedAvatar(const std::string& uid,
|
||||||
|
const std::string& mime,
|
||||||
|
const std::string& dataBase64);
|
||||||
|
// Record just the source url for a uid (upsert), so it survives to
|
||||||
|
// be re-fetched after the user goes offline.
|
||||||
|
Api::Result<void> putCachedAvatarUrl(const std::string& uid,
|
||||||
|
const std::string& url);
|
||||||
|
|
||||||
// ===== Subscriptions =====
|
// ===== Subscriptions =====
|
||||||
|
|
||||||
// Subscriber info
|
// Subscriber info
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ namespace Echoion::Api::Events
|
|||||||
struct PlaylistLoadStarted {
|
struct PlaylistLoadStarted {
|
||||||
std::string playlistId;
|
std::string playlistId;
|
||||||
uint64_t requestedByClientId;
|
uint64_t requestedByClientId;
|
||||||
uint64_t databasePlaylistId;
|
uint64_t databasePlaylistId = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PlaylistTrackLoaded {
|
struct PlaylistTrackLoaded {
|
||||||
@@ -110,7 +110,7 @@ namespace Echoion::Api::Events
|
|||||||
TrackInfo track;
|
TrackInfo track;
|
||||||
uint32_t loadedCount;
|
uint32_t loadedCount;
|
||||||
uint32_t totalCount;
|
uint32_t totalCount;
|
||||||
uint64_t databasePlaylistId;
|
uint64_t databasePlaylistId = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PlaylistLoadCompleted {
|
struct PlaylistLoadCompleted {
|
||||||
@@ -133,22 +133,6 @@ namespace Echoion::Api::Events
|
|||||||
uint64_t clientId;
|
uint64_t clientId;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Connection events
|
|
||||||
struct ClientConnected {
|
|
||||||
ClientInfo client;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ClientDisconnected {
|
|
||||||
uint64_t clientId;
|
|
||||||
std::string reason;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct ChannelChanged {
|
|
||||||
uint64_t clientId;
|
|
||||||
uint64_t oldChannelId;
|
|
||||||
uint64_t newChannelId;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Error events
|
// Error events
|
||||||
struct PlaybackError {
|
struct PlaybackError {
|
||||||
ErrorCode code;
|
ErrorCode code;
|
||||||
@@ -156,45 +140,9 @@ namespace Echoion::Api::Events
|
|||||||
std::optional<TrackInfo> track;
|
std::optional<TrackInfo> track;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NetworkError {
|
|
||||||
std::string url;
|
|
||||||
ErrorCode code;
|
|
||||||
std::string message;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Configuration events
|
// Configuration events
|
||||||
struct ConfigReloaded {
|
struct ConfigReloaded {
|
||||||
BotConfig newConfig;
|
BotConfig newConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ConfigChanged {
|
|
||||||
std::string key;
|
|
||||||
std::string oldValue;
|
|
||||||
std::string newValue;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Cache events
|
|
||||||
struct CacheHit {
|
|
||||||
std::string key;
|
|
||||||
std::string type;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct CacheMiss {
|
|
||||||
std::string key;
|
|
||||||
std::string type;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct CacheEvicted {
|
|
||||||
std::string key;
|
|
||||||
std::string reason;
|
|
||||||
};
|
|
||||||
|
|
||||||
// Database persistence events (for audit/logging)
|
|
||||||
struct DatabasePersisted {
|
|
||||||
std::string entityType; // "queue", "playback", ...
|
|
||||||
std::string operation; // "insert", "update", "delete"
|
|
||||||
bool success;
|
|
||||||
std::optional<std::string> error;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Echoion::Api::Events
|
} // namespace Echoion::Api::Events
|
||||||
@@ -21,7 +21,7 @@ namespace Echoion::Api
|
|||||||
struct QueueEntry;
|
struct QueueEntry;
|
||||||
struct PlaylistInfo;
|
struct PlaylistInfo;
|
||||||
|
|
||||||
// Minimal PlaybackState for Plugin
|
// Minimal playback state for the host boundary.
|
||||||
struct PlaybackSummary {
|
struct PlaybackSummary {
|
||||||
std::optional<TrackSummary> currentTrack;
|
std::optional<TrackSummary> currentTrack;
|
||||||
bool isPlaying = false;
|
bool isPlaying = false;
|
||||||
@@ -42,7 +42,7 @@ namespace Echoion::Api
|
|||||||
using CoreCreateFunc = std::function<CoreInterfacePtr()>;
|
using CoreCreateFunc = std::function<CoreInterfacePtr()>;
|
||||||
using CoreDestroyFunc = std::function<void(ICoreInterface*)>;
|
using CoreDestroyFunc = std::function<void(ICoreInterface*)>;
|
||||||
|
|
||||||
// Core interface that the Plugin will use to communicate with the Core
|
// Core interface used by the standalone host to communicate with Core.
|
||||||
// MINIMAL VERSION - breaks dependencies on Core-specific types
|
// MINIMAL VERSION - breaks dependencies on Core-specific types
|
||||||
class ICoreInterface
|
class ICoreInterface
|
||||||
{
|
{
|
||||||
@@ -51,7 +51,7 @@ namespace Echoion::Api
|
|||||||
virtual ~ICoreInterface() = default;
|
virtual ~ICoreInterface() = default;
|
||||||
|
|
||||||
// Lifecycle
|
// Lifecycle
|
||||||
// Plugin passes config file path, Core loads config internally
|
// The host passes a config path; Core loads it internally.
|
||||||
virtual Result<void>
|
virtual Result<void>
|
||||||
initialize(const std::filesystem::path& configPath) = 0;
|
initialize(const std::filesystem::path& configPath) = 0;
|
||||||
virtual Result<void> shutdown() = 0;
|
virtual Result<void> shutdown() = 0;
|
||||||
@@ -149,6 +149,28 @@ namespace Echoion::Api
|
|||||||
getConfigHandle() const = 0;
|
getConfigHandle() const = 0;
|
||||||
virtual Result<void>
|
virtual Result<void>
|
||||||
updateConfigFromHandle(AppConfigHandle config) = 0;
|
updateConfigFromHandle(AppConfigHandle config) = 0;
|
||||||
|
|
||||||
|
// Reload configuration from the config file on disk.
|
||||||
|
// NOTE: append-only. ICoreInterface is the hot-reload ABI contract
|
||||||
|
// between the (already-loaded) Plugin and a freshly reloaded Core.
|
||||||
|
// Inserting/removing a virtual method anywhere above shifts every
|
||||||
|
// later vtable slot, so the old Plugin would call the wrong methods
|
||||||
|
// on the new Core (state-transfer corruption on hot reload). Only
|
||||||
|
// ever add new virtuals at the very end.
|
||||||
|
virtual Result<void> reloadConfig() = 0;
|
||||||
|
|
||||||
|
// Managed extension reconciliation for the host updater. The
|
||||||
|
// request and response are versioned JSON documents so the plugin
|
||||||
|
// package format can evolve without exposing Core implementation
|
||||||
|
// types here. Append-only ABI: do not move this entry above
|
||||||
|
// existing methods.
|
||||||
|
[[nodiscard]] virtual Result<std::string>
|
||||||
|
managePluginsJson(const std::string& /*requestJson*/)
|
||||||
|
{
|
||||||
|
return fail(
|
||||||
|
ErrorCode::NotSupported,
|
||||||
|
"managed plugin updates are not supported by this Core");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Echoion::Api
|
} // namespace Echoion::Api
|
||||||
@@ -36,16 +36,135 @@ namespace Echoion::Api
|
|||||||
getClients() = 0;
|
getClients() = 0;
|
||||||
[[nodiscard]] virtual Result<std::optional<ClientInfo>>
|
[[nodiscard]] virtual Result<std::optional<ClientInfo>>
|
||||||
getClient(uint64_t clientId) = 0;
|
getClient(uint64_t clientId) = 0;
|
||||||
|
// Network address of a client as reported by TeamSpeak
|
||||||
|
// (CONNECTION_CLIENT_IP). Requires the bot to hold the
|
||||||
|
// b_client_remoteaddress_view permission; hosts that cannot
|
||||||
|
// resolve the address return nullopt.
|
||||||
|
[[nodiscard]] virtual Result<std::optional<std::string>>
|
||||||
|
getClientIp(uint64_t /*clientId*/)
|
||||||
|
{
|
||||||
|
return std::optional<std::string>{};
|
||||||
|
}
|
||||||
|
// Local filesystem path of the client's avatar image as cached
|
||||||
|
// by the TeamSpeak client (getAvatar). The cache is only
|
||||||
|
// populated for clients the TS client has seen; nullopt when the
|
||||||
|
// client has no avatar or it is not (yet) downloaded.
|
||||||
|
[[nodiscard]] virtual Result<std::optional<std::string>>
|
||||||
|
getClientAvatarPath(uint64_t /*clientId*/)
|
||||||
|
{
|
||||||
|
return std::optional<std::string>{};
|
||||||
|
}
|
||||||
|
// The client's myTeamSpeak avatar URL, if set. Modern clients store
|
||||||
|
// their avatar as a public HTTPS URL (CLIENT_MYTS_AVATAR, formatted
|
||||||
|
// "<version>,<url>") rather than the legacy file-transfer avatar.
|
||||||
|
// Returns the bare URL, or nullopt when unset/legacy.
|
||||||
|
[[nodiscard]] virtual Result<std::optional<std::string>>
|
||||||
|
getClientAvatarUrl(uint64_t /*clientId*/)
|
||||||
|
{
|
||||||
|
return std::optional<std::string>{};
|
||||||
|
}
|
||||||
|
// Actively fetch a client's avatar from the server into `destDir`
|
||||||
|
// (used when it isn't in the TS client's own cache — e.g. the
|
||||||
|
// client is not in view). Returns the local path once the file is
|
||||||
|
// present; returns nullopt when the client has no avatar or the
|
||||||
|
// download was just triggered and hasn't finished yet (a later
|
||||||
|
// call returns the path). Downloads run asynchronously.
|
||||||
|
[[nodiscard]] virtual Result<std::optional<std::string>>
|
||||||
|
requestClientAvatar(uint64_t /*clientId*/,
|
||||||
|
const std::string& /*destDir*/)
|
||||||
|
{
|
||||||
|
return std::optional<std::string>{};
|
||||||
|
}
|
||||||
virtual Result<void> moveClient(uint64_t clientId,
|
virtual Result<void> moveClient(uint64_t clientId,
|
||||||
uint64_t channelId) = 0;
|
uint64_t channelId) = 0;
|
||||||
virtual Result<void> kickClient(uint64_t clientId,
|
virtual Result<void> kickClient(uint64_t clientId,
|
||||||
const std::string& reason) = 0;
|
const std::string& reason) = 0;
|
||||||
|
virtual Result<void>
|
||||||
|
kickClientFromChannel(uint64_t /*clientId*/,
|
||||||
|
const std::string& /*reason*/)
|
||||||
|
{
|
||||||
|
return fail(ErrorCode::NotSupported,
|
||||||
|
"channel kick is not supported by this host");
|
||||||
|
}
|
||||||
|
virtual Result<void> banClient(uint64_t /*clientId*/,
|
||||||
|
uint64_t /*durationSeconds*/,
|
||||||
|
const std::string& /*reason*/)
|
||||||
|
{
|
||||||
|
return fail(ErrorCode::NotSupported,
|
||||||
|
"bans are not supported by this host");
|
||||||
|
}
|
||||||
|
[[nodiscard]] virtual Result<std::vector<BanInfo>> getBans()
|
||||||
|
{
|
||||||
|
return fail(ErrorCode::NotSupported,
|
||||||
|
"ban listing is not supported by this host");
|
||||||
|
}
|
||||||
|
virtual Result<void> unban(uint64_t /*banId*/)
|
||||||
|
{
|
||||||
|
return fail(ErrorCode::NotSupported,
|
||||||
|
"unban is not supported by this host");
|
||||||
|
}
|
||||||
|
|
||||||
// Channel operations
|
// Channel operations
|
||||||
[[nodiscard]] virtual Result<std::vector<ChannelInfo>>
|
[[nodiscard]] virtual Result<std::vector<ChannelInfo>>
|
||||||
getChannels() const = 0;
|
getChannels() const = 0;
|
||||||
[[nodiscard]] virtual Result<std::optional<ChannelInfo>>
|
[[nodiscard]] virtual Result<std::optional<ChannelInfo>>
|
||||||
getChannel(uint64_t channelId) const = 0;
|
getChannel(uint64_t channelId) const = 0;
|
||||||
|
virtual Result<uint64_t>
|
||||||
|
createChannel(const ChannelCreateOptions& /*options*/)
|
||||||
|
{
|
||||||
|
return fail(ErrorCode::NotSupported,
|
||||||
|
"channel creation is not supported by this host");
|
||||||
|
}
|
||||||
|
virtual Result<void>
|
||||||
|
editChannel(uint64_t /*channelId*/,
|
||||||
|
const ChannelEditOptions& /*options*/)
|
||||||
|
{
|
||||||
|
return fail(ErrorCode::NotSupported,
|
||||||
|
"channel editing is not supported by this host");
|
||||||
|
}
|
||||||
|
virtual Result<void> reorderChannel(uint64_t /*channelId*/,
|
||||||
|
uint64_t /*parentId*/,
|
||||||
|
uint64_t /*orderAfterId*/)
|
||||||
|
{
|
||||||
|
return fail(ErrorCode::NotSupported,
|
||||||
|
"channel reordering is not supported by this host");
|
||||||
|
}
|
||||||
|
virtual Result<void> deleteChannel(uint64_t /*channelId*/,
|
||||||
|
bool /*force*/)
|
||||||
|
{
|
||||||
|
return fail(ErrorCode::NotSupported,
|
||||||
|
"channel deletion is not supported by this host");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Server-group administration. Membership changes use TeamSpeak's
|
||||||
|
// stable client database id, not the connection-scoped client id.
|
||||||
|
[[nodiscard]] virtual Result<std::vector<ServerGroupInfo>>
|
||||||
|
getServerGroups()
|
||||||
|
{
|
||||||
|
return fail(ErrorCode::NotSupported,
|
||||||
|
"server groups are not supported by this host");
|
||||||
|
}
|
||||||
|
virtual Result<void>
|
||||||
|
addClientToServerGroup(uint64_t /*groupId*/,
|
||||||
|
uint64_t /*clientDatabaseId*/)
|
||||||
|
{
|
||||||
|
return fail(
|
||||||
|
ErrorCode::NotSupported,
|
||||||
|
"server-group membership is not supported by this host");
|
||||||
|
}
|
||||||
|
virtual Result<void>
|
||||||
|
removeClientFromServerGroup(uint64_t /*groupId*/,
|
||||||
|
uint64_t /*clientDatabaseId*/)
|
||||||
|
{
|
||||||
|
return fail(
|
||||||
|
ErrorCode::NotSupported,
|
||||||
|
"server-group membership is not supported by this host");
|
||||||
|
}
|
||||||
|
[[nodiscard]] virtual Result<ServerInfo> getTeamSpeakServerInfo()
|
||||||
|
{
|
||||||
|
return fail(ErrorCode::NotSupported,
|
||||||
|
"server information is not supported by this host");
|
||||||
|
}
|
||||||
|
|
||||||
// Messaging
|
// Messaging
|
||||||
virtual Result<void>
|
virtual Result<void>
|
||||||
@@ -76,6 +195,19 @@ namespace Echoion::Api
|
|||||||
registerEventCallback(const EventCallback& callback) = 0;
|
registerEventCallback(const EventCallback& callback) = 0;
|
||||||
virtual void
|
virtual void
|
||||||
unregisterEventCallback(const EventCallback& callback) = 0;
|
unregisterEventCallback(const EventCallback& callback) = 0;
|
||||||
|
|
||||||
|
// Host-owned control plane. Keep this generic JSON operation at the
|
||||||
|
// very end of the ABI so updater/service operations can evolve
|
||||||
|
// without shifting existing vtable entries. Hosts that do not
|
||||||
|
// expose a control plane retain the previous behavior through this
|
||||||
|
// default.
|
||||||
|
[[nodiscard]] virtual Result<std::string>
|
||||||
|
hostControl(const std::string& /*method*/,
|
||||||
|
const std::string& /*requestJson*/)
|
||||||
|
{
|
||||||
|
return fail(ErrorCode::NotSupported,
|
||||||
|
"host control is not supported by this host");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Echoion::Api
|
} // namespace Echoion::Api
|
||||||
@@ -0,0 +1,207 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <echoion/api/module/Module.hpp>
|
||||||
|
#include <echoion/api/module/ModuleAbi.h>
|
||||||
|
|
||||||
|
#include <Void/Data/Json.hpp>
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <limits>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace Echoion::Api::Module
|
||||||
|
{
|
||||||
|
namespace Detail
|
||||||
|
{
|
||||||
|
inline echoion_string_view_v1
|
||||||
|
stringView(const std::string_view value) noexcept
|
||||||
|
{
|
||||||
|
return {.data = value.data(), .size = value.size()};
|
||||||
|
}
|
||||||
|
|
||||||
|
inline echoion_status_v1
|
||||||
|
status(const Void::Result::Result<void>& result) noexcept
|
||||||
|
{
|
||||||
|
return result ? ECHOION_STATUS_OK_V1 : ECHOION_STATUS_INTERNAL_V1;
|
||||||
|
}
|
||||||
|
} // namespace Detail
|
||||||
|
|
||||||
|
// Transitional adapter for existing C++ lifecycle implementations. The
|
||||||
|
// exported descriptor and calls are pure C. C++ ownership and exceptions
|
||||||
|
// remain confined to the module that created the opaque instance.
|
||||||
|
template <Void::Plugin::module_factory_fn Factory>
|
||||||
|
struct LegacyModuleAbi final {
|
||||||
|
struct Instance {
|
||||||
|
std::unique_ptr<Void::Plugin::IModule> module;
|
||||||
|
std::string readinessDetail;
|
||||||
|
};
|
||||||
|
|
||||||
|
static echoion_status_v1
|
||||||
|
create(const echoion_module_host_v1* host,
|
||||||
|
echoion_module_instance_v1* output) noexcept
|
||||||
|
{
|
||||||
|
static_cast<void>(host);
|
||||||
|
if (output == nullptr) {
|
||||||
|
return ECHOION_STATUS_INVALID_ARGUMENT_V1;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
auto module = Factory();
|
||||||
|
if (!module) {
|
||||||
|
return ECHOION_STATUS_INTERNAL_V1;
|
||||||
|
}
|
||||||
|
auto instance = std::make_unique<Instance>(Instance{
|
||||||
|
.module = std::move(module), .readinessDetail = {}});
|
||||||
|
*output = instance.release();
|
||||||
|
return ECHOION_STATUS_OK_V1;
|
||||||
|
} catch (...) {
|
||||||
|
return ECHOION_STATUS_INTERNAL_V1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void destroy(echoion_module_instance_v1 value) noexcept
|
||||||
|
{
|
||||||
|
std::unique_ptr<Instance> instance{
|
||||||
|
static_cast<Instance*>(value)};
|
||||||
|
}
|
||||||
|
|
||||||
|
static echoion_status_v1
|
||||||
|
activate(echoion_module_instance_v1 value) noexcept
|
||||||
|
{
|
||||||
|
Instance* instance = checked(value);
|
||||||
|
if (instance == nullptr) {
|
||||||
|
return ECHOION_STATUS_INVALID_ARGUMENT_V1;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
instance->module->on_load();
|
||||||
|
return ECHOION_STATUS_OK_V1;
|
||||||
|
} catch (...) {
|
||||||
|
return ECHOION_STATUS_INTERNAL_V1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static echoion_status_v1
|
||||||
|
quiesce(echoion_module_instance_v1 value,
|
||||||
|
const std::int64_t deadlineNanoseconds) noexcept
|
||||||
|
{
|
||||||
|
Instance* instance = checked(value);
|
||||||
|
if (instance == nullptr || deadlineNanoseconds < 0) {
|
||||||
|
return ECHOION_STATUS_INVALID_ARGUMENT_V1;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const auto deadline = std::chrono::steady_clock::time_point{
|
||||||
|
std::chrono::nanoseconds{deadlineNanoseconds}};
|
||||||
|
return Detail::status(instance->module->quiesce(deadline));
|
||||||
|
} catch (...) {
|
||||||
|
return ECHOION_STATUS_INTERNAL_V1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static echoion_status_v1
|
||||||
|
checkpoint(echoion_module_instance_v1 value,
|
||||||
|
echoion_write_bytes_fn_v1 writer,
|
||||||
|
void* writerContext) noexcept
|
||||||
|
{
|
||||||
|
Instance* instance = checked(value);
|
||||||
|
if (instance == nullptr || writer == nullptr) {
|
||||||
|
return ECHOION_STATUS_INVALID_ARGUMENT_V1;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const std::string encoded =
|
||||||
|
Void::Json::serialize(instance->module->checkpoint());
|
||||||
|
return writer(
|
||||||
|
writerContext,
|
||||||
|
{.data = reinterpret_cast<const std::uint8_t*>(
|
||||||
|
encoded.data()),
|
||||||
|
.size = encoded.size()});
|
||||||
|
} catch (...) {
|
||||||
|
return ECHOION_STATUS_INTERNAL_V1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static echoion_status_v1
|
||||||
|
restore(echoion_module_instance_v1 value,
|
||||||
|
const echoion_bytes_view_v1 state) noexcept
|
||||||
|
{
|
||||||
|
Instance* instance = checked(value);
|
||||||
|
if (instance == nullptr ||
|
||||||
|
(state.data == nullptr && state.size != 0)) {
|
||||||
|
return ECHOION_STATUS_INVALID_ARGUMENT_V1;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const std::string_view encoded =
|
||||||
|
state.size == 0
|
||||||
|
? std::string_view{}
|
||||||
|
: std::string_view{
|
||||||
|
reinterpret_cast<const char*>(state.data),
|
||||||
|
state.size};
|
||||||
|
const auto parsed = Void::Json::parse(encoded);
|
||||||
|
if (!parsed) {
|
||||||
|
return ECHOION_STATUS_INVALID_ARGUMENT_V1;
|
||||||
|
}
|
||||||
|
return Detail::status(instance->module->restore(*parsed));
|
||||||
|
} catch (...) {
|
||||||
|
return ECHOION_STATUS_INTERNAL_V1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static echoion_status_v1
|
||||||
|
readiness(echoion_module_instance_v1 value,
|
||||||
|
echoion_module_readiness_v1* output) noexcept
|
||||||
|
{
|
||||||
|
Instance* instance = checked(value);
|
||||||
|
if (instance == nullptr || output == nullptr ||
|
||||||
|
output->struct_size < sizeof(echoion_module_readiness_v1)) {
|
||||||
|
return ECHOION_STATUS_INVALID_ARGUMENT_V1;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const auto result = instance->module->readiness();
|
||||||
|
instance->readinessDetail = result.detail;
|
||||||
|
output->ready = result.ready ? 1U : 0U;
|
||||||
|
output->detail =
|
||||||
|
Detail::stringView(instance->readinessDetail);
|
||||||
|
return ECHOION_STATUS_OK_V1;
|
||||||
|
} catch (...) {
|
||||||
|
return ECHOION_STATUS_INTERNAL_V1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static echoion_status_v1
|
||||||
|
deactivate(echoion_module_instance_v1 value) noexcept
|
||||||
|
{
|
||||||
|
Instance* instance = checked(value);
|
||||||
|
if (instance == nullptr) {
|
||||||
|
return ECHOION_STATUS_INVALID_ARGUMENT_V1;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return Detail::status(instance->module->deactivate());
|
||||||
|
} catch (...) {
|
||||||
|
return ECHOION_STATUS_INTERNAL_V1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline static const echoion_module_api_v1 api{
|
||||||
|
.struct_size = sizeof(echoion_module_api_v1),
|
||||||
|
.abi_version = ECHOION_MODULE_ABI_VERSION,
|
||||||
|
.create = create,
|
||||||
|
.destroy = destroy,
|
||||||
|
.activate = activate,
|
||||||
|
.quiesce = quiesce,
|
||||||
|
.checkpoint = checkpoint,
|
||||||
|
.restore = restore,
|
||||||
|
.readiness = readiness,
|
||||||
|
.deactivate = deactivate,
|
||||||
|
.reserved = {},
|
||||||
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
[[nodiscard]] static Instance*
|
||||||
|
checked(echoion_module_instance_v1 value) noexcept
|
||||||
|
{
|
||||||
|
return static_cast<Instance*>(value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Echoion::Api::Module
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <echoion/api/module/ModuleAbi.h>
|
||||||
|
|
||||||
|
#include <Void/Plugin/Module.hpp>
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#if defined(ECHOION_MODULE_BUILD)
|
||||||
|
#define ECHOION_MODULE_EXPORT __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define ECHOION_MODULE_EXPORT __declspec(dllimport)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define ECHOION_MODULE_EXPORT __attribute__((visibility("default")))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace Echoion::Api::Module
|
||||||
|
{
|
||||||
|
using Void::Plugin::ActivationPolicy;
|
||||||
|
using Void::Plugin::IModule;
|
||||||
|
using Void::Plugin::module_factory_fn;
|
||||||
|
using Void::Plugin::module_query_fn;
|
||||||
|
using Void::Plugin::ModuleDependency;
|
||||||
|
using Void::Plugin::ModuleDescriptor;
|
||||||
|
using Void::Plugin::ModuleHost;
|
||||||
|
using Void::Plugin::ModuleReadiness;
|
||||||
|
|
||||||
|
inline constexpr auto descriptorVersion =
|
||||||
|
Void::Plugin::MODULE_DESCRIPTOR_VERSION;
|
||||||
|
inline constexpr const char* querySymbol = "echoion_module_query";
|
||||||
|
inline constexpr const char* stableQuerySymbol =
|
||||||
|
ECHOION_MODULE_ABI_QUERY_SYMBOL;
|
||||||
|
|
||||||
|
} // namespace Echoion::Api::Module
|
||||||
|
|
||||||
|
extern "C" ECHOION_MODULE_EXPORT const Void::Plugin::ModuleDescriptor*
|
||||||
|
echoion_module_query();
|
||||||
@@ -0,0 +1,131 @@
|
|||||||
|
#ifndef ECHOION_API_MODULE_MODULE_ABI_H
|
||||||
|
#define ECHOION_API_MODULE_MODULE_ABI_H
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
#if defined(ECHOION_MODULE_BUILD)
|
||||||
|
#define ECHOION_MODULE_ABI_EXPORT __declspec(dllexport)
|
||||||
|
#else
|
||||||
|
#define ECHOION_MODULE_ABI_EXPORT __declspec(dllimport)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#define ECHOION_MODULE_ABI_EXPORT __attribute__((visibility("default")))
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define ECHOION_MODULE_ABI_VERSION 1U
|
||||||
|
#define ECHOION_MODULE_ABI_QUERY_SYMBOL "echoion_module_abi_query"
|
||||||
|
|
||||||
|
typedef struct echoion_string_view_v1 {
|
||||||
|
const char* data;
|
||||||
|
size_t size;
|
||||||
|
} echoion_string_view_v1;
|
||||||
|
|
||||||
|
typedef struct echoion_bytes_view_v1 {
|
||||||
|
const uint8_t* data;
|
||||||
|
size_t size;
|
||||||
|
} echoion_bytes_view_v1;
|
||||||
|
|
||||||
|
typedef enum echoion_status_v1 {
|
||||||
|
ECHOION_STATUS_OK_V1 = 0,
|
||||||
|
ECHOION_STATUS_INVALID_ARGUMENT_V1 = 1,
|
||||||
|
ECHOION_STATUS_INCOMPATIBLE_V1 = 2,
|
||||||
|
ECHOION_STATUS_UNAVAILABLE_V1 = 3,
|
||||||
|
ECHOION_STATUS_INTERNAL_V1 = 4
|
||||||
|
} echoion_status_v1;
|
||||||
|
|
||||||
|
typedef enum echoion_activation_policy_v1 {
|
||||||
|
ECHOION_ACTIVATION_RELOADABLE_V1 = 0,
|
||||||
|
ECHOION_ACTIVATION_RESTART_REQUIRED_V1 = 1,
|
||||||
|
ECHOION_ACTIVATION_INSTALLER_REQUIRED_V1 = 2
|
||||||
|
} echoion_activation_policy_v1;
|
||||||
|
|
||||||
|
typedef void* echoion_module_instance_v1;
|
||||||
|
|
||||||
|
typedef echoion_status_v1 (*echoion_write_bytes_fn_v1)(
|
||||||
|
void* context, echoion_bytes_view_v1 value);
|
||||||
|
|
||||||
|
typedef echoion_status_v1 (*echoion_query_service_fn_v1)(
|
||||||
|
void* context, echoion_string_view_v1 service_id, uint32_t minimum_version,
|
||||||
|
const void** service);
|
||||||
|
|
||||||
|
typedef void (*echoion_log_fn_v1)(void* context, uint32_t level,
|
||||||
|
echoion_string_view_v1 message);
|
||||||
|
|
||||||
|
typedef struct echoion_module_host_v1 {
|
||||||
|
size_t struct_size;
|
||||||
|
uint32_t abi_version;
|
||||||
|
void* context;
|
||||||
|
echoion_query_service_fn_v1 query_service;
|
||||||
|
echoion_log_fn_v1 log;
|
||||||
|
const void* reserved[8];
|
||||||
|
} echoion_module_host_v1;
|
||||||
|
|
||||||
|
typedef struct echoion_module_readiness_v1 {
|
||||||
|
size_t struct_size;
|
||||||
|
uint8_t ready;
|
||||||
|
uint8_t reserved_bytes[7];
|
||||||
|
echoion_string_view_v1 detail;
|
||||||
|
} echoion_module_readiness_v1;
|
||||||
|
|
||||||
|
typedef struct echoion_module_api_v1 {
|
||||||
|
size_t struct_size;
|
||||||
|
uint32_t abi_version;
|
||||||
|
echoion_status_v1 (*create)(const echoion_module_host_v1* host,
|
||||||
|
echoion_module_instance_v1* instance);
|
||||||
|
void (*destroy)(echoion_module_instance_v1 instance);
|
||||||
|
echoion_status_v1 (*activate)(echoion_module_instance_v1 instance);
|
||||||
|
echoion_status_v1 (*quiesce)(echoion_module_instance_v1 instance,
|
||||||
|
int64_t steady_clock_deadline_nanoseconds);
|
||||||
|
echoion_status_v1 (*checkpoint)(echoion_module_instance_v1 instance,
|
||||||
|
echoion_write_bytes_fn_v1 writer,
|
||||||
|
void* writer_context);
|
||||||
|
echoion_status_v1 (*restore)(echoion_module_instance_v1 instance,
|
||||||
|
echoion_bytes_view_v1 state);
|
||||||
|
echoion_status_v1 (*readiness)(echoion_module_instance_v1 instance,
|
||||||
|
echoion_module_readiness_v1* readiness);
|
||||||
|
echoion_status_v1 (*deactivate)(echoion_module_instance_v1 instance);
|
||||||
|
const void* reserved[8];
|
||||||
|
} echoion_module_api_v1;
|
||||||
|
|
||||||
|
typedef struct echoion_module_dependency_v1 {
|
||||||
|
size_t struct_size;
|
||||||
|
echoion_string_view_v1 component_id;
|
||||||
|
echoion_string_view_v1 version_range;
|
||||||
|
echoion_string_view_v1 abi_hash;
|
||||||
|
uint8_t optional;
|
||||||
|
uint8_t reserved_bytes[7];
|
||||||
|
} echoion_module_dependency_v1;
|
||||||
|
|
||||||
|
typedef struct echoion_module_descriptor_v1 {
|
||||||
|
size_t struct_size;
|
||||||
|
uint32_t abi_version;
|
||||||
|
echoion_string_view_v1 component_id;
|
||||||
|
uint32_t version_major;
|
||||||
|
uint32_t version_minor;
|
||||||
|
uint32_t version_patch;
|
||||||
|
echoion_string_view_v1 version_prerelease;
|
||||||
|
echoion_string_view_v1 abi_hash;
|
||||||
|
const echoion_module_dependency_v1* dependencies;
|
||||||
|
size_t dependency_count;
|
||||||
|
echoion_activation_policy_v1 activation_policy;
|
||||||
|
const echoion_module_api_v1* api;
|
||||||
|
const void* reserved[8];
|
||||||
|
} echoion_module_descriptor_v1;
|
||||||
|
|
||||||
|
typedef const echoion_module_descriptor_v1* (*echoion_module_abi_query_fn_v1)(
|
||||||
|
void);
|
||||||
|
|
||||||
|
ECHOION_MODULE_ABI_EXPORT const echoion_module_descriptor_v1*
|
||||||
|
echoion_module_abi_query(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <PluginTypes.hpp>
|
||||||
|
#include <TrackTypes.hpp>
|
||||||
|
#include <Types.hpp>
|
||||||
|
#include <Void/Plugin/Module.hpp>
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace Echoion::Api
|
||||||
|
{
|
||||||
|
struct ExtensionCommand {
|
||||||
|
std::string name;
|
||||||
|
std::vector<std::string> aliases;
|
||||||
|
std::string description;
|
||||||
|
std::string usage;
|
||||||
|
std::uint8_t category = 5;
|
||||||
|
bool adminOnly = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ExtensionRpc {
|
||||||
|
std::string name;
|
||||||
|
bool adminOnly = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ExtensionMediaSource {
|
||||||
|
std::string name;
|
||||||
|
bool supportsSearch = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ExtensionWebAsset {
|
||||||
|
std::string id;
|
||||||
|
std::string javascript;
|
||||||
|
std::string css;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ExtensionCommandRequest {
|
||||||
|
std::string command;
|
||||||
|
std::string arguments;
|
||||||
|
std::uint64_t clientId = 0;
|
||||||
|
std::string invokerName;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ExtensionRpcRequest {
|
||||||
|
std::string method;
|
||||||
|
std::string params;
|
||||||
|
std::uint64_t clientId = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ExtensionStream {
|
||||||
|
std::string url;
|
||||||
|
bool localFile = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Native, trusted Echoion extension contract. Calls are always made while
|
||||||
|
// the host holds a Void::Plugin::PluginHandle, so a hot reload cannot
|
||||||
|
// unmap code that is still executing.
|
||||||
|
class IExtensionPlugin : public Void::Plugin::IModule
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
[[nodiscard]] virtual std::vector<ExtensionCommand> commands() const
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
[[nodiscard]] virtual std::vector<ExtensionRpc> rpcMethods() const
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
[[nodiscard]] virtual std::vector<ExtensionMediaSource> mediaSources() const
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
[[nodiscard]] virtual std::vector<ExtensionWebAsset> webAssets() const
|
||||||
|
{
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
virtual Result<std::string> executeCommand(
|
||||||
|
const ExtensionCommandRequest&)
|
||||||
|
{
|
||||||
|
return fail(ErrorCode::NotSupported, "extension command is not supported");
|
||||||
|
}
|
||||||
|
virtual Result<std::string> callRpc(const ExtensionRpcRequest&)
|
||||||
|
{
|
||||||
|
return fail(ErrorCode::NotSupported, "extension RPC is not supported");
|
||||||
|
}
|
||||||
|
virtual void onEvent(const PluginEvent&) {}
|
||||||
|
[[nodiscard]] virtual bool canHandleMedia(
|
||||||
|
std::string_view, const std::string&) const
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
virtual Result<SearchResult> searchMedia(
|
||||||
|
std::string_view, std::string_view)
|
||||||
|
{
|
||||||
|
return fail(ErrorCode::NotSupported, "extension search is not supported");
|
||||||
|
}
|
||||||
|
virtual Result<TrackInfo> resolveMedia(
|
||||||
|
std::string_view, const std::string&)
|
||||||
|
{
|
||||||
|
return fail(ErrorCode::NotSupported, "extension resolve is not supported");
|
||||||
|
}
|
||||||
|
virtual Result<ExtensionStream> streamMedia(
|
||||||
|
std::string_view, const TrackInfo&)
|
||||||
|
{
|
||||||
|
return fail(ErrorCode::NotSupported, "extension stream is not supported");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifndef PLUGIN
|
|
||||||
#include <ConfigTypes.hpp>
|
#include <ConfigTypes.hpp>
|
||||||
#endif
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@@ -38,10 +36,17 @@ namespace Echoion::Api
|
|||||||
SeekPosition,
|
SeekPosition,
|
||||||
HotReloadRequested,
|
HotReloadRequested,
|
||||||
HotReloadCompleted,
|
HotReloadCompleted,
|
||||||
ConfigurationChanged
|
ConfigurationChanged,
|
||||||
|
// Appended: fired once the TeamSpeak connection is fully established
|
||||||
|
// (client list available), so the core can resolve online subscribers.
|
||||||
|
ConnectionEstablished,
|
||||||
|
// Appended for the authoritative TeamSpeak directory cache. Hosts may
|
||||||
|
// emit either event after refreshing their local topology mirror.
|
||||||
|
ClientUpdated,
|
||||||
|
ChannelUpdated
|
||||||
};
|
};
|
||||||
|
|
||||||
// Minimal track info for Plugin (no internal types)
|
// Minimal track info for the host boundary (no internal types)
|
||||||
struct TrackSummary {
|
struct TrackSummary {
|
||||||
std::string id;
|
std::string id;
|
||||||
std::string title;
|
std::string title;
|
||||||
@@ -51,27 +56,30 @@ namespace Echoion::Api
|
|||||||
|
|
||||||
struct PluginEvent {
|
struct PluginEvent {
|
||||||
PluginEventType type;
|
PluginEventType type;
|
||||||
std::optional<std::string> clientName;
|
std::optional<std::string> clientName = {};
|
||||||
std::optional<TrackSummary>
|
std::optional<TrackSummary> trackSummary =
|
||||||
trackSummary; // Opaque summary instead of full TrackInfo
|
{}; // Opaque summary instead of full TrackInfo
|
||||||
uint64_t clientId = 0;
|
uint64_t clientId = 0;
|
||||||
std::optional<uint64_t> targetChannelId;
|
std::optional<uint64_t> targetChannelId = {};
|
||||||
std::optional<std::string> message;
|
std::optional<std::string> message = {};
|
||||||
std::optional<float> volume;
|
std::optional<float> volume = {};
|
||||||
std::optional<int> queuePosition;
|
std::optional<int> queuePosition = {};
|
||||||
std::chrono::system_clock::time_point timestamp;
|
std::chrono::system_clock::time_point timestamp = {};
|
||||||
};
|
};
|
||||||
|
|
||||||
// ===== Connection Types =====
|
// ===== Connection Types =====
|
||||||
|
|
||||||
struct ClientInfo {
|
struct ClientInfo {
|
||||||
uint64_t id = 0;
|
uint64_t id = 0;
|
||||||
|
std::optional<uint64_t> databaseId;
|
||||||
std::string nickname;
|
std::string nickname;
|
||||||
std::optional<std::string> uniqueIdentifier;
|
std::optional<std::string> uniqueIdentifier;
|
||||||
uint64_t channelId = 0;
|
uint64_t channelId = 0;
|
||||||
bool isTalking = false;
|
bool isTalking = false;
|
||||||
bool isMuted = false;
|
bool isMuted = false;
|
||||||
bool isDeafened = false;
|
bool isDeafened = false;
|
||||||
|
bool isAway = false;
|
||||||
|
bool isQuery = false;
|
||||||
std::vector<uint64_t> serverGroups;
|
std::vector<uint64_t> serverGroups;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -81,11 +89,48 @@ namespace Echoion::Api
|
|||||||
std::optional<uint64_t> parentId;
|
std::optional<uint64_t> parentId;
|
||||||
uint64_t order = 0;
|
uint64_t order = 0;
|
||||||
bool isDefault = false;
|
bool isDefault = false;
|
||||||
|
bool isPermanent = false;
|
||||||
|
bool isSemiPermanent = false;
|
||||||
bool hasPassword = false;
|
bool hasPassword = false;
|
||||||
uint32_t maxClients = 0;
|
uint32_t maxClients = 0;
|
||||||
uint32_t currentClients = 0;
|
uint32_t currentClients = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ChannelCreateOptions {
|
||||||
|
std::string name;
|
||||||
|
std::optional<uint64_t> parentId;
|
||||||
|
std::optional<uint64_t> orderAfterId;
|
||||||
|
std::optional<std::string> topic;
|
||||||
|
std::optional<std::string> description;
|
||||||
|
std::optional<std::string> password;
|
||||||
|
uint32_t maxClients = 0;
|
||||||
|
bool permanent = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ChannelEditOptions {
|
||||||
|
std::optional<std::string> name;
|
||||||
|
std::optional<std::string> topic;
|
||||||
|
std::optional<std::string> description;
|
||||||
|
std::optional<std::string> password;
|
||||||
|
std::optional<uint32_t> maxClients;
|
||||||
|
std::optional<bool> permanent;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ServerGroupInfo {
|
||||||
|
uint64_t id = 0;
|
||||||
|
std::string name;
|
||||||
|
bool isDefault = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BanInfo {
|
||||||
|
uint64_t id = 0;
|
||||||
|
std::optional<std::string> uniqueIdentifier;
|
||||||
|
std::optional<std::string> nickname;
|
||||||
|
std::string reason;
|
||||||
|
uint64_t createdAt = 0;
|
||||||
|
uint64_t durationSeconds = 0; // 0 means permanent
|
||||||
|
};
|
||||||
|
|
||||||
struct ServerInfo {
|
struct ServerInfo {
|
||||||
uint64_t id = 0;
|
uint64_t id = 0;
|
||||||
std::string name;
|
std::string name;
|
||||||
@@ -95,22 +140,6 @@ namespace Echoion::Api
|
|||||||
uint64_t defaultChannelId = 0;
|
uint64_t defaultChannelId = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ServerConfig is needed for Plugin's connectToServer()
|
|
||||||
// This is a minimal version without dependencies on AudioTypes, etc.
|
|
||||||
// Available to both Core and Plugin
|
|
||||||
#ifdef PLUGIN
|
|
||||||
struct ServerConfig {
|
|
||||||
std::string address;
|
|
||||||
uint16_t port = 0;
|
|
||||||
std::string serverPassword;
|
|
||||||
std::string nickname;
|
|
||||||
std::optional<std::string> defaultChannelId;
|
|
||||||
std::optional<std::string> channelPassword;
|
|
||||||
std::vector<uint64_t> adminGroups;
|
|
||||||
std::vector<uint64_t> djGroups;
|
|
||||||
std::vector<uint64_t> bannedGroups;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
// ===== Callback Types =====
|
// ===== Callback Types =====
|
||||||
|
|
||||||
using EventCallback = std::function<void(const PluginEvent&)>;
|
using EventCallback = std::function<void(const PluginEvent&)>;
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Void/Data/Json.hpp>
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <expected>
|
||||||
|
#include <optional>
|
||||||
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
|
namespace Echoion::Api::Plugin::ShortUrl
|
||||||
|
{
|
||||||
|
template <typename T> using Result = std::expected<T, std::string>;
|
||||||
|
|
||||||
|
[[nodiscard]] Result<Void::Json::Value>
|
||||||
|
parseConfigObject(const char* config);
|
||||||
|
[[nodiscard]] Result<std::string>
|
||||||
|
requireString(const Void::Json::Value& object, std::string_view key);
|
||||||
|
[[nodiscard]] Result<std::string>
|
||||||
|
optionalString(const Void::Json::Value& object, std::string_view key,
|
||||||
|
std::string_view fallback = {});
|
||||||
|
[[nodiscard]] Result<bool> optionalBool(const Void::Json::Value& object,
|
||||||
|
std::string_view key,
|
||||||
|
bool fallback);
|
||||||
|
[[nodiscard]] Result<std::int64_t>
|
||||||
|
optionalInteger(const Void::Json::Value& object, std::string_view key,
|
||||||
|
std::int64_t fallback, std::int64_t minimum,
|
||||||
|
std::int64_t maximum);
|
||||||
|
|
||||||
|
[[nodiscard]] bool
|
||||||
|
containsControlCharacters(std::string_view value) noexcept;
|
||||||
|
[[nodiscard]] std::string trimAscii(std::string_view value);
|
||||||
|
[[nodiscard]] bool isHeaderName(std::string_view value) noexcept;
|
||||||
|
[[nodiscard]] bool isBase62(std::string_view value) noexcept;
|
||||||
|
|
||||||
|
/// Validate an absolute HTTP(S) URL without making a network request.
|
||||||
|
[[nodiscard]] Result<void>
|
||||||
|
validateHttpUrl(std::string_view value, bool requireHttps,
|
||||||
|
std::size_t maximumLength = 8192);
|
||||||
|
|
||||||
|
/// Reject address literals and well-known hostnames that are not publicly
|
||||||
|
/// routable. DNS-backed validation lives in the external provider because
|
||||||
|
/// only it opens outbound connections.
|
||||||
|
[[nodiscard]] bool isObviouslyPrivateHost(std::string_view host) noexcept;
|
||||||
|
|
||||||
|
/// Expand ${url} and ${env:NAME}. Environment variables are read without
|
||||||
|
/// being copied into diagnostics; a missing variable reports only its name.
|
||||||
|
[[nodiscard]] Result<std::string>
|
||||||
|
expandTemplate(std::string_view input, std::string_view url,
|
||||||
|
bool encodeSubstitutions = false);
|
||||||
|
|
||||||
|
} // namespace Echoion::Api::Plugin::ShortUrl
|
||||||
@@ -58,7 +58,79 @@ namespace Echoion::Api
|
|||||||
// Server info
|
// Server info
|
||||||
GetServerInfo,
|
GetServerInfo,
|
||||||
RequestLoginToken,
|
RequestLoginToken,
|
||||||
ValidateLoginToken
|
ValidateLoginToken,
|
||||||
|
|
||||||
|
// Playback mode (appended; numeric values are server-internal and
|
||||||
|
// only need to stay self-consistent — the wire contract is the name)
|
||||||
|
ToggleShuffle,
|
||||||
|
ToggleRepeat,
|
||||||
|
ShuffleQueue,
|
||||||
|
|
||||||
|
// Library (appended)
|
||||||
|
GetPlaylist, // playlist contents by id
|
||||||
|
GetHistory, // recently played tracks
|
||||||
|
GetStats, // playback statistics
|
||||||
|
|
||||||
|
// Web UI (appended)
|
||||||
|
GetFavorites, // authenticated user's favorites
|
||||||
|
AddFavorite, // add a track to favorites
|
||||||
|
RemoveFavorite, // remove by track url
|
||||||
|
VoteSkip, // vote to skip the current track
|
||||||
|
Announce, // admin: broadcast an announcement
|
||||||
|
GetAggregateStats, // server-wide dashboard statistics
|
||||||
|
|
||||||
|
// Web UI round 2 (appended)
|
||||||
|
AuthenticateByAddress, // sign in by matching the caller's IP against
|
||||||
|
// online subscribers' TeamSpeak addresses
|
||||||
|
RestartWebInterface, // admin: stop+start the web server in place
|
||||||
|
ToggleAutoplay, // admin: flip radio mode (autoplay)
|
||||||
|
|
||||||
|
// Web UI round 3 (appended)
|
||||||
|
GetUserPrefs, // per-user preferences (language, …) from the kv store
|
||||||
|
SetUserPrefs, // update per-user preferences; keys shared with the
|
||||||
|
// chat commands (e.g. !lang) so both stay in sync
|
||||||
|
|
||||||
|
// Values 49-51 are reserved for retired browser features.
|
||||||
|
// Web UI round 5 (appended): lyrics for the current track (lrclib)
|
||||||
|
GetLyrics = 52, // plain + time-synced lyrics for the now-playing track
|
||||||
|
|
||||||
|
// Values 53-66 belonged to the removed experimental TeamSpeak
|
||||||
|
// listening-room API. Keep later values stable for stored audit rows.
|
||||||
|
GetCapabilities = 67,
|
||||||
|
GetPluginExtensions,
|
||||||
|
PluginCall,
|
||||||
|
|
||||||
|
// Values 70-72 are reserved for retired browser features.
|
||||||
|
// TeamSpeak directory and administration; 53-66 stay reserved.
|
||||||
|
GetTeamSpeakDirectory = 73,
|
||||||
|
MoveTeamSpeakClient,
|
||||||
|
KickTeamSpeakClient,
|
||||||
|
BanTeamSpeakClient,
|
||||||
|
GetTeamSpeakBans,
|
||||||
|
UnbanTeamSpeakClient,
|
||||||
|
CreateTeamSpeakChannel,
|
||||||
|
EditTeamSpeakChannel,
|
||||||
|
ReorderTeamSpeakChannel,
|
||||||
|
DeleteTeamSpeakChannel,
|
||||||
|
GetTeamSpeakServerGroups,
|
||||||
|
AddTeamSpeakServerGroupMember,
|
||||||
|
RemoveTeamSpeakServerGroupMember,
|
||||||
|
SendTeamSpeakPrivateMessage,
|
||||||
|
SendTeamSpeakChannelMessage,
|
||||||
|
SendTeamSpeakServerMessage,
|
||||||
|
|
||||||
|
// Component updater (append-only; values 89-99).
|
||||||
|
GetUpdateStatus,
|
||||||
|
GetUpdateConfig,
|
||||||
|
SetUpdateConfig,
|
||||||
|
CheckForUpdates,
|
||||||
|
ApplyUpdate,
|
||||||
|
RollbackUpdate,
|
||||||
|
ConfirmUnsignedUpdate,
|
||||||
|
PreviewUpdateTransaction,
|
||||||
|
ApplyUpdateTransaction,
|
||||||
|
RollbackUpdateGeneration,
|
||||||
|
GetUpdateHistory
|
||||||
};
|
};
|
||||||
|
|
||||||
struct RpcRequest {
|
struct RpcRequest {
|
||||||
@@ -102,6 +174,7 @@ namespace Echoion::Api
|
|||||||
std::chrono::milliseconds playbackPosition;
|
std::chrono::milliseconds playbackPosition;
|
||||||
BotConfig config;
|
BotConfig config;
|
||||||
std::map<std::string, std::string> sessionData;
|
std::map<std::string, std::string> sessionData;
|
||||||
|
bool autoplay = false;
|
||||||
|
|
||||||
[[nodiscard]] bool shouldPreservePlayback() const noexcept
|
[[nodiscard]] bool shouldPreservePlayback() const noexcept
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -18,7 +18,13 @@ namespace Echoion::Api
|
|||||||
SoundCloud,
|
SoundCloud,
|
||||||
Spotify,
|
Spotify,
|
||||||
LocalFile,
|
LocalFile,
|
||||||
URL
|
URL,
|
||||||
|
// Appended after URL so existing uint8_t-serialized history rows
|
||||||
|
// keep their meaning.
|
||||||
|
Yandex,
|
||||||
|
// Media returned by an extension plugin. Keep this distinct from
|
||||||
|
// Unknown so source allowlists never have to permit unknown values.
|
||||||
|
Plugin
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TrackInfo {
|
struct TrackInfo {
|
||||||
@@ -31,15 +37,15 @@ namespace Echoion::Api
|
|||||||
TrackSource source;
|
TrackSource source;
|
||||||
std::string originalUrl;
|
std::string originalUrl;
|
||||||
std::optional<std::string>
|
std::optional<std::string>
|
||||||
shortenedUrl; // faumaray.ru shortened link
|
shortenedUrl; // provider-generated public link
|
||||||
std::optional<std::string> streamUrl;
|
std::optional<std::string> streamUrl;
|
||||||
std::optional<AudioStreamInfo> audioInfo;
|
std::optional<AudioStreamInfo> audioInfo;
|
||||||
std::chrono::system_clock::time_point addedAt;
|
std::chrono::system_clock::time_point addedAt;
|
||||||
std::string requestedBy;
|
std::string requestedBy;
|
||||||
|
|
||||||
// Format track as markdown link: [Title](shortenedUrl)
|
// Format track as markdown link: [Title](shortenedUrl)
|
||||||
// Only uses shortened URL (faumaray), returns empty string if not
|
// Only uses a successfully generated shortened URL; returns no link
|
||||||
// available
|
// if unavailable.
|
||||||
[[nodiscard]] std::string formatWithLink() const
|
[[nodiscard]] std::string formatWithLink() const
|
||||||
{
|
{
|
||||||
if (shortenedUrl.has_value() && !shortenedUrl->empty()) {
|
if (shortenedUrl.has_value() && !shortenedUrl->empty()) {
|
||||||
@@ -50,8 +56,8 @@ namespace Echoion::Api
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Format track with artist and link
|
// Format track with artist and link
|
||||||
// Only uses shortened URL (faumaray), returns text only if not
|
// Only uses a successfully generated shortened URL; returns text if
|
||||||
// available
|
// unavailable.
|
||||||
[[nodiscard]] std::string formatWithArtistAndLink() const
|
[[nodiscard]] std::string formatWithArtistAndLink() const
|
||||||
{
|
{
|
||||||
std::string displayTitle = title;
|
std::string displayTitle = title;
|
||||||
|
|||||||
@@ -0,0 +1,189 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Canonicalize, hash, classify, and version Echoion module contracts."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import hashlib
|
||||||
|
import json
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
from dataclasses import dataclass
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import Any
|
||||||
|
|
||||||
|
|
||||||
|
SEMVER = re.compile(
|
||||||
|
r"^(?P<major>0|[1-9][0-9]*)\."
|
||||||
|
r"(?P<minor>0|[1-9][0-9]*)\."
|
||||||
|
r"(?P<patch>0|[1-9][0-9]*)$"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def load_contract(path: Path) -> Any:
|
||||||
|
with path.open(encoding="utf-8") as source:
|
||||||
|
contract = json.load(source)
|
||||||
|
if not isinstance(contract, dict) or contract.get("schemaVersion") != 1:
|
||||||
|
raise ValueError(f"{path}: unsupported ABI contract schema")
|
||||||
|
return contract
|
||||||
|
|
||||||
|
|
||||||
|
def canonical_bytes(contract: Any) -> bytes:
|
||||||
|
return (
|
||||||
|
json.dumps(
|
||||||
|
contract,
|
||||||
|
ensure_ascii=False,
|
||||||
|
sort_keys=True,
|
||||||
|
separators=(",", ":"),
|
||||||
|
)
|
||||||
|
+ "\n"
|
||||||
|
).encode()
|
||||||
|
|
||||||
|
|
||||||
|
def contract_hash(contract: Any) -> str:
|
||||||
|
return "sha256:" + hashlib.sha256(canonical_bytes(contract)).hexdigest()
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class Compatibility:
|
||||||
|
compatible: bool
|
||||||
|
changed: bool
|
||||||
|
|
||||||
|
|
||||||
|
def compare_contract(old: Any, new: Any) -> Compatibility:
|
||||||
|
"""Return whether new is an append-only superset of old."""
|
||||||
|
if type(old) is not type(new):
|
||||||
|
return Compatibility(False, True)
|
||||||
|
if isinstance(old, dict):
|
||||||
|
changed = len(old) != len(new)
|
||||||
|
for key, old_value in old.items():
|
||||||
|
if key not in new:
|
||||||
|
return Compatibility(False, True)
|
||||||
|
result = compare_contract(old_value, new[key])
|
||||||
|
if not result.compatible:
|
||||||
|
return result
|
||||||
|
changed = changed or result.changed
|
||||||
|
return Compatibility(True, changed)
|
||||||
|
if isinstance(old, list):
|
||||||
|
if len(new) < len(old):
|
||||||
|
return Compatibility(False, True)
|
||||||
|
changed = len(new) != len(old)
|
||||||
|
for index, old_value in enumerate(old):
|
||||||
|
result = compare_contract(old_value, new[index])
|
||||||
|
if not result.compatible:
|
||||||
|
return result
|
||||||
|
changed = changed or result.changed
|
||||||
|
return Compatibility(True, changed)
|
||||||
|
return Compatibility(old == new, old != new)
|
||||||
|
|
||||||
|
|
||||||
|
def classify(
|
||||||
|
old_contract: Any,
|
||||||
|
new_contract: Any,
|
||||||
|
old_source_sha: str,
|
||||||
|
new_source_sha: str,
|
||||||
|
kind: str,
|
||||||
|
) -> str:
|
||||||
|
if old_source_sha == new_source_sha:
|
||||||
|
if canonical_bytes(old_contract) != canonical_bytes(new_contract):
|
||||||
|
raise ValueError("ABI contract changed without a source SHA change")
|
||||||
|
return "unchanged"
|
||||||
|
if kind in {"executable", "assets"}:
|
||||||
|
return "patch"
|
||||||
|
|
||||||
|
comparison = compare_contract(old_contract, new_contract)
|
||||||
|
if not comparison.compatible:
|
||||||
|
return "major"
|
||||||
|
return "minor" if comparison.changed else "patch"
|
||||||
|
|
||||||
|
|
||||||
|
def derive_version(current: str, change: str) -> str:
|
||||||
|
match = SEMVER.fullmatch(current)
|
||||||
|
if match is None:
|
||||||
|
raise ValueError(f"component version is not stable SemVer: {current}")
|
||||||
|
major, minor, patch = (
|
||||||
|
int(match.group("major")),
|
||||||
|
int(match.group("minor")),
|
||||||
|
int(match.group("patch")),
|
||||||
|
)
|
||||||
|
if change == "unchanged":
|
||||||
|
return current
|
||||||
|
if change == "patch":
|
||||||
|
return f"{major}.{minor}.{patch + 1}"
|
||||||
|
if change == "minor":
|
||||||
|
return f"{major}.{minor + 1}.0"
|
||||||
|
if change == "major":
|
||||||
|
return f"{major + 1}.0.0"
|
||||||
|
raise ValueError(f"unsupported change classification: {change}")
|
||||||
|
|
||||||
|
|
||||||
|
def write_or_print(payload: bytes, output: Path | None) -> None:
|
||||||
|
if output is None:
|
||||||
|
sys.stdout.buffer.write(payload)
|
||||||
|
return
|
||||||
|
temporary = output.with_name(output.name + ".tmp")
|
||||||
|
temporary.write_bytes(payload)
|
||||||
|
temporary.replace(output)
|
||||||
|
|
||||||
|
|
||||||
|
def build_parser() -> argparse.ArgumentParser:
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
subparsers = parser.add_subparsers(dest="command", required=True)
|
||||||
|
|
||||||
|
canonical = subparsers.add_parser("canonicalize")
|
||||||
|
canonical.add_argument("contract", type=Path)
|
||||||
|
canonical.add_argument("--output", type=Path)
|
||||||
|
|
||||||
|
digest = subparsers.add_parser("hash")
|
||||||
|
digest.add_argument("contract", type=Path)
|
||||||
|
|
||||||
|
classify_parser = subparsers.add_parser("classify")
|
||||||
|
classify_parser.add_argument("old_contract", type=Path)
|
||||||
|
classify_parser.add_argument("new_contract", type=Path)
|
||||||
|
classify_parser.add_argument("--old-source-sha", required=True)
|
||||||
|
classify_parser.add_argument("--new-source-sha", required=True)
|
||||||
|
classify_parser.add_argument(
|
||||||
|
"--kind",
|
||||||
|
choices=("module", "library", "executable", "assets"),
|
||||||
|
default="module",
|
||||||
|
)
|
||||||
|
|
||||||
|
derive = subparsers.add_parser("derive-version")
|
||||||
|
derive.add_argument("current")
|
||||||
|
derive.add_argument(
|
||||||
|
"change", choices=("unchanged", "patch", "minor", "major")
|
||||||
|
)
|
||||||
|
return parser
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> int:
|
||||||
|
args = build_parser().parse_args()
|
||||||
|
try:
|
||||||
|
if args.command == "canonicalize":
|
||||||
|
write_or_print(
|
||||||
|
canonical_bytes(load_contract(args.contract)), args.output
|
||||||
|
)
|
||||||
|
elif args.command == "hash":
|
||||||
|
print(contract_hash(load_contract(args.contract)))
|
||||||
|
elif args.command == "classify":
|
||||||
|
print(
|
||||||
|
classify(
|
||||||
|
load_contract(args.old_contract),
|
||||||
|
load_contract(args.new_contract),
|
||||||
|
args.old_source_sha,
|
||||||
|
args.new_source_sha,
|
||||||
|
args.kind,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
elif args.command == "derive-version":
|
||||||
|
print(derive_version(args.current, args.change))
|
||||||
|
else:
|
||||||
|
raise AssertionError(args.command)
|
||||||
|
except (OSError, json.JSONDecodeError, ValueError) as error:
|
||||||
|
print(f"abi-contract: {error}", file=sys.stderr)
|
||||||
|
return 2
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
raise SystemExit(main())
|
||||||
@@ -0,0 +1,319 @@
|
|||||||
|
#include <echoion/api/plugin/ShortUrlSupport.hpp>
|
||||||
|
|
||||||
|
#include <Void/Net/Url.hpp>
|
||||||
|
#include <Void/Text/Url.hpp>
|
||||||
|
|
||||||
|
#include <boost/asio/ip/address.hpp>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cctype>
|
||||||
|
#include <cmath>
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <format>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
|
namespace Echoion::Api::Plugin::ShortUrl
|
||||||
|
{
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
[[nodiscard]] bool validEnvironmentName(std::string_view name) noexcept
|
||||||
|
{
|
||||||
|
if (name.empty() ||
|
||||||
|
!(std::isalpha(static_cast<unsigned char>(name.front())) != 0 ||
|
||||||
|
name.front() == '_')) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return std::ranges::all_of(
|
||||||
|
name.substr(1), [](const char character) {
|
||||||
|
const auto value = static_cast<unsigned char>(character);
|
||||||
|
return std::isalnum(value) != 0 || character == '_';
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool
|
||||||
|
isPrivateV4(const boost::asio::ip::address_v4 address) noexcept
|
||||||
|
{
|
||||||
|
const auto value = address.to_uint();
|
||||||
|
const auto first = static_cast<unsigned>((value >> 24U) & 0xffU);
|
||||||
|
const auto second = static_cast<unsigned>((value >> 16U) & 0xffU);
|
||||||
|
const auto third = static_cast<unsigned>((value >> 8U) & 0xffU);
|
||||||
|
|
||||||
|
return first == 0U || first == 10U || first == 127U ||
|
||||||
|
(first == 100U && second >= 64U && second <= 127U) ||
|
||||||
|
(first == 169U && second == 254U) ||
|
||||||
|
(first == 172U && second >= 16U && second <= 31U) ||
|
||||||
|
(first == 192U && second == 168U) ||
|
||||||
|
(first == 192U && second == 0U && third <= 2U) ||
|
||||||
|
(first == 198U && (second == 18U || second == 19U)) ||
|
||||||
|
(first == 198U && second == 51U && third == 100U) ||
|
||||||
|
(first == 203U && second == 0U && third == 113U) ||
|
||||||
|
first >= 224U;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool
|
||||||
|
isPrivateV6(const boost::asio::ip::address_v6 address) noexcept
|
||||||
|
{
|
||||||
|
const auto bytes = address.to_bytes();
|
||||||
|
if (address.is_unspecified() || address.is_loopback() ||
|
||||||
|
address.is_link_local() || address.is_multicast()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (address.is_v4_mapped()) {
|
||||||
|
const boost::asio::ip::address_v4::bytes_type mapped{
|
||||||
|
bytes[12], bytes[13], bytes[14], bytes[15]};
|
||||||
|
return isPrivateV4(boost::asio::ip::address_v4{mapped});
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool uniqueLocal = (bytes[0] & 0xfeU) == 0xfcU;
|
||||||
|
const bool documentation = bytes[0] == 0x20U && bytes[1] == 0x01U &&
|
||||||
|
bytes[2] == 0x0dU && bytes[3] == 0xb8U;
|
||||||
|
return uniqueLocal || documentation;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
Result<Void::Json::Value> parseConfigObject(const char* config)
|
||||||
|
{
|
||||||
|
if (config == nullptr || *config == '\0') {
|
||||||
|
return std::unexpected{"plugin configuration is required"};
|
||||||
|
}
|
||||||
|
auto parsed = Void::Json::parse(config);
|
||||||
|
if (!parsed) {
|
||||||
|
return std::unexpected{
|
||||||
|
std::format("invalid plugin configuration at {}:{}: {}",
|
||||||
|
parsed.error().line, parsed.error().col,
|
||||||
|
parsed.error().message)};
|
||||||
|
}
|
||||||
|
if (!parsed->is_object()) {
|
||||||
|
return std::unexpected{
|
||||||
|
"plugin configuration must be a JSON object"};
|
||||||
|
}
|
||||||
|
return std::move(*parsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
Result<std::string> requireString(const Void::Json::Value& object,
|
||||||
|
const std::string_view key)
|
||||||
|
{
|
||||||
|
const auto* value = object.find(key);
|
||||||
|
if (value == nullptr || !value->is_string() ||
|
||||||
|
value->as_string().empty()) {
|
||||||
|
return std::unexpected{std::format(
|
||||||
|
"configuration field '{}' must be a non-empty string", key)};
|
||||||
|
}
|
||||||
|
return value->as_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
Result<std::string> optionalString(const Void::Json::Value& object,
|
||||||
|
const std::string_view key,
|
||||||
|
const std::string_view fallback)
|
||||||
|
{
|
||||||
|
const auto* value = object.find(key);
|
||||||
|
if (value == nullptr) {
|
||||||
|
return std::string{fallback};
|
||||||
|
}
|
||||||
|
if (!value->is_string()) {
|
||||||
|
return std::unexpected{
|
||||||
|
std::format("configuration field '{}' must be a string", key)};
|
||||||
|
}
|
||||||
|
return value->as_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
Result<bool> optionalBool(const Void::Json::Value& object,
|
||||||
|
const std::string_view key, const bool fallback)
|
||||||
|
{
|
||||||
|
const auto* value = object.find(key);
|
||||||
|
if (value == nullptr) {
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
if (!value->is_bool()) {
|
||||||
|
return std::unexpected{
|
||||||
|
std::format("configuration field '{}' must be a boolean", key)};
|
||||||
|
}
|
||||||
|
return value->as_bool();
|
||||||
|
}
|
||||||
|
|
||||||
|
Result<std::int64_t> optionalInteger(const Void::Json::Value& object,
|
||||||
|
const std::string_view key,
|
||||||
|
const std::int64_t fallback,
|
||||||
|
const std::int64_t minimum,
|
||||||
|
const std::int64_t maximum)
|
||||||
|
{
|
||||||
|
const auto* value = object.find(key);
|
||||||
|
if (value == nullptr) {
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
if (!value->is_number()) {
|
||||||
|
return std::unexpected{std::format(
|
||||||
|
"configuration field '{}' must be an integer", key)};
|
||||||
|
}
|
||||||
|
const auto number = value->as_number();
|
||||||
|
if (!std::isfinite(number) || std::floor(number) != number ||
|
||||||
|
number < static_cast<double>(minimum) ||
|
||||||
|
number > static_cast<double>(maximum)) {
|
||||||
|
return std::unexpected{std::format(
|
||||||
|
"configuration field '{}' must be between {} and {}", key,
|
||||||
|
minimum, maximum)};
|
||||||
|
}
|
||||||
|
return static_cast<std::int64_t>(number);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool containsControlCharacters(const std::string_view value) noexcept
|
||||||
|
{
|
||||||
|
return std::ranges::any_of(value, [](const char character) {
|
||||||
|
const auto byte = static_cast<unsigned char>(character);
|
||||||
|
return byte < 0x20U || byte == 0x7fU;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string trimAscii(const std::string_view value)
|
||||||
|
{
|
||||||
|
const auto isSpace = [](const char character) {
|
||||||
|
return std::isspace(static_cast<unsigned char>(character)) != 0;
|
||||||
|
};
|
||||||
|
const auto first = std::ranges::find_if_not(value, isSpace);
|
||||||
|
const auto last =
|
||||||
|
std::find_if_not(value.rbegin(), value.rend(), isSpace).base();
|
||||||
|
if (first >= last) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
return {first, last};
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isHeaderName(const std::string_view value) noexcept
|
||||||
|
{
|
||||||
|
if (value.empty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
constexpr std::string_view separators{"()<>@,;:\\\"/[]?={} \t"};
|
||||||
|
return std::ranges::all_of(value, [separators](const char character) {
|
||||||
|
const auto byte = static_cast<unsigned char>(character);
|
||||||
|
return byte > 0x20U && byte < 0x7fU &&
|
||||||
|
separators.find(character) == std::string_view::npos;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isBase62(const std::string_view value) noexcept
|
||||||
|
{
|
||||||
|
return !value.empty() && std::ranges::all_of(value, [](const char c) {
|
||||||
|
return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') ||
|
||||||
|
(c >= 'a' && c <= 'z');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Result<void> validateHttpUrl(const std::string_view value,
|
||||||
|
const bool requireHttps,
|
||||||
|
const std::size_t maximumLength)
|
||||||
|
{
|
||||||
|
if (value.empty() || value.size() > maximumLength ||
|
||||||
|
containsControlCharacters(value) ||
|
||||||
|
std::ranges::any_of(value, [](const char c) {
|
||||||
|
return std::isspace(static_cast<unsigned char>(c)) != 0;
|
||||||
|
})) {
|
||||||
|
return std::unexpected{
|
||||||
|
"URL is empty, too long, or contains whitespace"};
|
||||||
|
}
|
||||||
|
const auto parsed = Void::Net::Url::parse(value);
|
||||||
|
if (!parsed || parsed->host.empty() ||
|
||||||
|
(parsed->scheme != "http" && parsed->scheme != "https")) {
|
||||||
|
return std::unexpected{"URL must be an absolute HTTP(S) URL"};
|
||||||
|
}
|
||||||
|
if (requireHttps && parsed->scheme != "https") {
|
||||||
|
return std::unexpected{"URL must use HTTPS"};
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto schemeEnd = value.find("://");
|
||||||
|
const auto authorityEnd = value.find_first_of("/?#", schemeEnd + 3U);
|
||||||
|
const auto authority =
|
||||||
|
value.substr(schemeEnd + 3U, authorityEnd == std::string_view::npos
|
||||||
|
? std::string_view::npos
|
||||||
|
: authorityEnd - schemeEnd - 3U);
|
||||||
|
if (authority.find('@') != std::string_view::npos) {
|
||||||
|
return std::unexpected{"URL userinfo is not allowed"};
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isObviouslyPrivateHost(const std::string_view host) noexcept
|
||||||
|
{
|
||||||
|
std::string lower;
|
||||||
|
lower.reserve(host.size());
|
||||||
|
std::ranges::transform(
|
||||||
|
host, std::back_inserter(lower), [](const char c) {
|
||||||
|
return static_cast<char>(
|
||||||
|
std::tolower(static_cast<unsigned char>(c)));
|
||||||
|
});
|
||||||
|
while (!lower.empty() && lower.back() == '.') {
|
||||||
|
lower.pop_back();
|
||||||
|
}
|
||||||
|
if (lower == "localhost" || lower.ends_with(".localhost") ||
|
||||||
|
lower.ends_with(".local") || lower.ends_with(".internal")) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::system::error_code error;
|
||||||
|
const auto address = boost::asio::ip::make_address(lower, error);
|
||||||
|
if (error) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return address.is_v4() ? isPrivateV4(address.to_v4())
|
||||||
|
: isPrivateV6(address.to_v6());
|
||||||
|
}
|
||||||
|
|
||||||
|
Result<std::string> expandTemplate(const std::string_view input,
|
||||||
|
const std::string_view url,
|
||||||
|
const bool encodeSubstitutions)
|
||||||
|
{
|
||||||
|
const auto appendReplacement =
|
||||||
|
[encodeSubstitutions](std::string& destination,
|
||||||
|
const std::string_view replacement) {
|
||||||
|
if (encodeSubstitutions) {
|
||||||
|
destination.append(
|
||||||
|
Void::Encoding::Url::query_encode(replacement));
|
||||||
|
} else {
|
||||||
|
destination.append(replacement);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
std::string output;
|
||||||
|
output.reserve(input.size() + url.size());
|
||||||
|
std::size_t position{};
|
||||||
|
while (position < input.size()) {
|
||||||
|
const auto marker = input.find("${", position);
|
||||||
|
if (marker == std::string_view::npos) {
|
||||||
|
output.append(input.substr(position));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
output.append(input.substr(position, marker - position));
|
||||||
|
const auto end = input.find('}', marker + 2U);
|
||||||
|
if (end == std::string_view::npos) {
|
||||||
|
return std::unexpected{"unterminated template placeholder"};
|
||||||
|
}
|
||||||
|
const auto token = input.substr(marker + 2U, end - marker - 2U);
|
||||||
|
if (token == "url") {
|
||||||
|
appendReplacement(output, url);
|
||||||
|
} else if (token.starts_with("env:")) {
|
||||||
|
const auto name = token.substr(4U);
|
||||||
|
if (!validEnvironmentName(name)) {
|
||||||
|
return std::unexpected{
|
||||||
|
"invalid environment placeholder name"};
|
||||||
|
}
|
||||||
|
const std::string ownedName{name};
|
||||||
|
const char* value = std::getenv(ownedName.c_str());
|
||||||
|
if (value == nullptr) {
|
||||||
|
return std::unexpected{std::format(
|
||||||
|
"required environment variable '{}' is not set", name)};
|
||||||
|
}
|
||||||
|
if (containsControlCharacters(value)) {
|
||||||
|
return std::unexpected{std::format(
|
||||||
|
"environment variable '{}' contains control characters",
|
||||||
|
name)};
|
||||||
|
}
|
||||||
|
appendReplacement(output, value);
|
||||||
|
} else {
|
||||||
|
return std::unexpected{std::format(
|
||||||
|
"unsupported template placeholder '${{{}}}'", token)};
|
||||||
|
}
|
||||||
|
position = end + 1U;
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Echoion::Api::Plugin::ShortUrl
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import copy
|
||||||
|
import importlib.util
|
||||||
|
import sys
|
||||||
|
import unittest
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
ROOT = Path(__file__).resolve().parents[1]
|
||||||
|
SPEC = importlib.util.spec_from_file_location(
|
||||||
|
"abi_contract", ROOT / "scripts" / "abi_contract.py"
|
||||||
|
)
|
||||||
|
assert SPEC is not None and SPEC.loader is not None
|
||||||
|
ABI = importlib.util.module_from_spec(SPEC)
|
||||||
|
sys.modules[SPEC.name] = ABI
|
||||||
|
SPEC.loader.exec_module(ABI)
|
||||||
|
|
||||||
|
|
||||||
|
class AbiContractTests(unittest.TestCase):
|
||||||
|
def setUp(self) -> None:
|
||||||
|
self.contract = ABI.load_contract(
|
||||||
|
ROOT / "abi" / "echoion-module-v1.json"
|
||||||
|
)
|
||||||
|
|
||||||
|
def classify(self, updated: object, old: str = "a", new: str = "b") -> str:
|
||||||
|
return ABI.classify(self.contract, updated, old, new, "module")
|
||||||
|
|
||||||
|
def test_canonical_hash_is_stable(self) -> None:
|
||||||
|
reordered = {
|
||||||
|
key: self.contract[key] for key in reversed(self.contract.keys())
|
||||||
|
}
|
||||||
|
self.assertEqual(
|
||||||
|
ABI.contract_hash(self.contract), ABI.contract_hash(reordered)
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_unchanged_source_reuses_version_and_artifact(self) -> None:
|
||||||
|
self.assertEqual(
|
||||||
|
ABI.classify(
|
||||||
|
self.contract, copy.deepcopy(self.contract), "same", "same", "module"
|
||||||
|
),
|
||||||
|
"unchanged",
|
||||||
|
)
|
||||||
|
self.assertEqual(ABI.derive_version("2.0.0", "unchanged"), "2.0.0")
|
||||||
|
|
||||||
|
def test_implementation_only_change_increments_patch(self) -> None:
|
||||||
|
self.assertEqual(self.classify(copy.deepcopy(self.contract)), "patch")
|
||||||
|
self.assertEqual(ABI.derive_version("2.0.0", "patch"), "2.0.1")
|
||||||
|
|
||||||
|
def test_append_only_change_increments_minor(self) -> None:
|
||||||
|
updated = copy.deepcopy(self.contract)
|
||||||
|
updated["types"][0]["fields"].append(
|
||||||
|
{
|
||||||
|
"name": "future_field",
|
||||||
|
"type": "uint64_t",
|
||||||
|
"ownership": "value",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
self.assertEqual(self.classify(updated), "minor")
|
||||||
|
self.assertEqual(ABI.derive_version("2.3.9", "minor"), "2.4.0")
|
||||||
|
|
||||||
|
def test_reordered_retyped_and_renamed_fields_are_breaking(self) -> None:
|
||||||
|
for mutate in (
|
||||||
|
lambda fields: fields.reverse(),
|
||||||
|
lambda fields: fields[0].update(type="uint64_t"),
|
||||||
|
lambda fields: fields[0].update(name="renamed"),
|
||||||
|
):
|
||||||
|
with self.subTest(mutate=mutate):
|
||||||
|
updated = copy.deepcopy(self.contract)
|
||||||
|
mutate(updated["types"][0]["fields"])
|
||||||
|
self.assertEqual(self.classify(updated), "major")
|
||||||
|
self.assertEqual(ABI.derive_version("2.3.9", "major"), "3.0.0")
|
||||||
|
|
||||||
|
def test_contract_change_without_source_change_is_rejected(self) -> None:
|
||||||
|
updated = copy.deepcopy(self.contract)
|
||||||
|
updated["types"].append({"name": "future", "fields": []})
|
||||||
|
with self.assertRaisesRegex(
|
||||||
|
ValueError, "without a source SHA change"
|
||||||
|
):
|
||||||
|
self.classify(updated, "same", "same")
|
||||||
|
|
||||||
|
def test_executable_and_assets_changes_increment_patch(self) -> None:
|
||||||
|
incompatible = {"schemaVersion": 1}
|
||||||
|
for kind in ("executable", "assets"):
|
||||||
|
with self.subTest(kind=kind):
|
||||||
|
self.assertEqual(
|
||||||
|
ABI.classify(
|
||||||
|
self.contract, incompatible, "old", "new", kind
|
||||||
|
),
|
||||||
|
"patch",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Compile the public module ABI as both C and C++."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
import subprocess
|
||||||
|
import tempfile
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
|
ROOT = Path(__file__).resolve().parents[1]
|
||||||
|
HEADER = ROOT / "include"
|
||||||
|
|
||||||
|
|
||||||
|
class ModuleAbiCTests(unittest.TestCase):
|
||||||
|
def compile(self, compiler: str, suffix: str, standard: str) -> None:
|
||||||
|
with tempfile.TemporaryDirectory(
|
||||||
|
prefix="echoion-module-abi."
|
||||||
|
) as directory:
|
||||||
|
source = Path(directory) / f"consumer.{suffix}"
|
||||||
|
source.write_text(
|
||||||
|
"""
|
||||||
|
#include <echoion/api/module/ModuleAbi.h>
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
#ifdef __cplusplus
|
||||||
|
echoion_module_descriptor_v1 descriptor = {};
|
||||||
|
#else
|
||||||
|
echoion_module_descriptor_v1 descriptor = {0};
|
||||||
|
#endif
|
||||||
|
descriptor.struct_size = sizeof(descriptor);
|
||||||
|
descriptor.abi_version = ECHOION_MODULE_ABI_VERSION;
|
||||||
|
return descriptor.api == 0 ? 0 : 1;
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
result = subprocess.run(
|
||||||
|
[
|
||||||
|
compiler,
|
||||||
|
standard,
|
||||||
|
"-Wall",
|
||||||
|
"-Wextra",
|
||||||
|
"-Wpedantic",
|
||||||
|
"-Werror",
|
||||||
|
"-I",
|
||||||
|
str(HEADER),
|
||||||
|
"-fsyntax-only",
|
||||||
|
str(source),
|
||||||
|
],
|
||||||
|
check=False,
|
||||||
|
text=True,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE,
|
||||||
|
)
|
||||||
|
self.assertEqual(result.returncode, 0, result.stderr)
|
||||||
|
|
||||||
|
def test_header_is_c11(self) -> None:
|
||||||
|
self.compile(os.environ.get("CC", "cc"), "c", "-std=c11")
|
||||||
|
|
||||||
|
def test_header_is_cpp20(self) -> None:
|
||||||
|
self.compile(os.environ.get("CXX", "c++"), "cpp", "-std=c++20")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Reference in new issue
Block a user