Squashed 'external/toxcore/c-toxcore/' changes from e29e185c03..f1df709b87
f1df709b87 feat: add ngc events 1b6c907235 refactor: Make event dispatch ordered by receive time. b7f9367f6f test: Upgrade cppcheck, fix some warnings. 766e62bc89 chore: Use `pkg_search_module` directly in cmake. 00ff078f91 cleanup: Use target_link_libraries directly in cmake. c58928cc89 chore: Add `IMPORTED_TARGET` to pkg-config packages. 895a6af122 cleanup: Remove NaCl support. 41dfb1c1c0 fix: unpack enum function names in event impl generator 447666d1a1 chore: Disable targets for cross-compilation. 572924e924 chore: Build a docker image with coverage info in it. 415cb78f5e cleanup: Some portability/warning fixes for Windows builds. 425216d9ec fix: Correct a use-after-free and fix some memory leaks. 4b1cfa3e08 refactor: Change all enum-like `#define` sequences into enums. d3c2704fa9 chore: Fix make_single_file to support core-only. 0ce46b644e refactor: Change the `TCP_PACKET_*` defines into an enum. 22cd38ad50 adopt event impl generation tool to #2392 f31ea1088a add the event impl generation tool 4e603bb613 refactor: Use `enum-from-int` rule from tokstyle. 19d8f180d6 chore: Update github actions `uses`. 6a895be0c7 test: Make esp32 build actually try to instantiate tox. 65d09c9bfb cleanup: Remove test net support. REVERT: e29e185c03 feat: add ngc events git-subtree-dir: external/toxcore/c-toxcore git-subtree-split: f1df709b8792da4c0e946d826b11df77d565064d
This commit is contained in:
@ -9,16 +9,12 @@ DHT_bootstrap_SOURCES = ../other/DHT_bootstrap.c \
|
||||
../other/bootstrap_node_packets.c
|
||||
|
||||
DHT_bootstrap_CFLAGS = -I$(top_srcdir)/other \
|
||||
$(LIBSODIUM_CFLAGS) \
|
||||
$(NACL_CFLAGS)
|
||||
$(LIBSODIUM_CFLAGS)
|
||||
|
||||
DHT_bootstrap_LDADD = $(LIBSODIUM_LDFLAGS) \
|
||||
$(NACL_LDFLAGS) \
|
||||
libmisc_tools.la \
|
||||
libtoxcore.la \
|
||||
$(LIBSODIUM_LIBS) \
|
||||
$(NACL_OBJECTS) \
|
||||
$(NACL_LIBS) \
|
||||
$(WINSOCK2_LIBS)
|
||||
|
||||
endif
|
||||
|
@ -8,9 +8,12 @@ set -e
|
||||
|
||||
CPPCHECK=("--enable=all")
|
||||
CPPCHECK+=("--inconclusive")
|
||||
CPPCHECK+=("--check-level=exhaustive")
|
||||
CPPCHECK+=("--inline-suppr")
|
||||
CPPCHECK+=("--library=other/docker/cppcheck/toxcore.cfg")
|
||||
CPPCHECK+=("--error-exitcode=1")
|
||||
# Used for VLA.
|
||||
CPPCHECK+=("--suppress=allocaCalled")
|
||||
# We don't cast function pointers, which cppcheck suggests here.
|
||||
CPPCHECK+=("--suppress=constParameterCallback")
|
||||
# False positives in switch statements.
|
||||
CPPCHECK+=("--suppress=knownConditionTrueFalse")
|
||||
# Cppcheck does not need standard library headers to get proper results.
|
||||
@ -19,27 +22,22 @@ CPPCHECK+=("--suppress=missingIncludeSystem")
|
||||
CPPCHECK+=("--suppress=signConversion")
|
||||
# TODO(iphydf): Fixed in the toxav refactor PR.
|
||||
CPPCHECK+=("--suppress=redundantAssignment")
|
||||
# We have some redundant nullptr checks in assertions
|
||||
CPPCHECK+=("--suppress=nullPointerRedundantCheck")
|
||||
# Triggers a false warning in group.c
|
||||
CPPCHECK+=("--suppress=AssignmentAddressToInteger")
|
||||
# TODO(sudden6): This triggers a false positive, check again later to enable it
|
||||
CPPCHECK+=("--suppress=arrayIndexOutOfBoundsCond")
|
||||
|
||||
# We're a library. This only works on whole programs.
|
||||
CPPCHECK_C=("--suppress=unusedFunction")
|
||||
|
||||
# We use this for VLAs.
|
||||
CPPCHECK_CXX+=("--suppress=allocaCalled")
|
||||
# False positive in auto_tests.
|
||||
CPPCHECK_CXX+=("--suppress=shadowArgument")
|
||||
CPPCHECK_CXX+=("--suppress=shadowFunction")
|
||||
# False positive for callback functions
|
||||
CPPCHECK_CXX+=("--suppress=constParameter")
|
||||
# False positive in group.c.
|
||||
# Using cppcheck-suppress claims the suppression is unused.
|
||||
CPPCHECK_CXX+=("--suppress=AssignmentAddressToInteger")
|
||||
# We use C style casts because we write C code.
|
||||
CPPCHECK_CXX+=("--suppress=cstyleCast")
|
||||
# Used in Messenger.c for a static_assert(...)
|
||||
CPPCHECK_CXX+=("--suppress=sizeofFunctionCall")
|
||||
|
||||
run() {
|
||||
echo "Running cppcheck in variant '$*'"
|
||||
cppcheck "${CPPCHECK[@]}" "${CPPCHECK_C[@]}" tox*/*.[ch] tox*/*/*.[ch] "${CPPFLAGS[@]}" "$@"
|
||||
cppcheck -j8 "${CPPCHECK[@]}" "${CPPCHECK_C[@]}" tox*/*.[ch] tox*/*/*.[ch] "${CPPFLAGS[@]}" "$@"
|
||||
cppcheck "${CPPCHECK[@]}" "${CPPCHECK_CXX[@]}" amalgamation.cc "${CPPFLAGS[@]}" "$@"
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,14 @@ add_executable(tox-bootstrapd
|
||||
src/tox-bootstrapd.c
|
||||
../bootstrap_node_packets.c
|
||||
../bootstrap_node_packets.h)
|
||||
target_link_modules(tox-bootstrapd toxcore ${LIBCONFIG_LIBRARIES})
|
||||
target_link_libraries(tox-bootstrapd PRIVATE ${LIBCONFIG_LIBRARIES})
|
||||
target_link_directories(tox-bootstrapd PRIVATE ${LIBCONFIG_LIBRARY_DIRS})
|
||||
target_include_directories(tox-bootstrapd SYSTEM PRIVATE ${LIBCONFIG_INCLUDE_DIRS})
|
||||
target_compile_options(tox-bootstrapd PRIVATE ${LIBCONFIG_CFLAGS_OTHER})
|
||||
if(TARGET toxcore_static)
|
||||
target_link_libraries(tox-bootstrapd PRIVATE toxcore_static)
|
||||
else()
|
||||
target_link_libraries(tox-bootstrapd PRIVATE toxcore_shared)
|
||||
endif()
|
||||
install(TARGETS tox-bootstrapd RUNTIME DESTINATION bin)
|
||||
install(FILES bash-completion/completions/tox-bootstrapd DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/bash-completion/completions")
|
||||
|
@ -1 +1 @@
|
||||
21cf23b1a2e46712663dc4f8daa322991af51b9e82626a127cf1bc8dc583b598 /usr/local/bin/tox-bootstrapd
|
||||
b0bd5099f2f77fbd540a5a929a23cece39ff95e3a66702a5381342d01775cbd3 /usr/local/bin/tox-bootstrapd
|
||||
|
@ -24,17 +24,13 @@ tox_bootstrapd_SOURCES = \
|
||||
tox_bootstrapd_CFLAGS = \
|
||||
-I$(top_srcdir)/other/bootstrap_daemon \
|
||||
$(LIBSODIUM_CFLAGS) \
|
||||
$(NACL_CFLAGS) \
|
||||
$(LIBCONFIG_CFLAGS)
|
||||
|
||||
tox_bootstrapd_LDADD = \
|
||||
$(LIBSODIUM_LDFLAGS) \
|
||||
$(NACL_LDFLAGS) \
|
||||
libtoxcore.la \
|
||||
$(LIBCONFIG_LIBS) \
|
||||
$(LIBSODIUM_LIBS) \
|
||||
$(NACL_OBJECTS) \
|
||||
$(NACL_LIBS)
|
||||
$(LIBSODIUM_LIBS)
|
||||
|
||||
bashcompdir = $(datarootdir)/bash-completion/completions
|
||||
dist_bashcomp_DATA = $(top_builddir)/other/bootstrap_daemon/bash-completion/completions/tox-bootstrapd
|
||||
|
@ -57,7 +57,7 @@ static void sleep_milliseconds(uint32_t ms)
|
||||
// returns 1 on success
|
||||
// 0 on failure - no keys were read or stored
|
||||
|
||||
static int manage_keys(DHT *dht, char *keys_file_path)
|
||||
static int manage_keys(DHT *dht, const char *keys_file_path)
|
||||
{
|
||||
enum { KEYS_SIZE = CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_SECRET_KEY_SIZE };
|
||||
uint8_t keys[KEYS_SIZE];
|
||||
|
@ -1,6 +1,27 @@
|
||||
################################################
|
||||
# autotools-linux
|
||||
FROM toxchat/nacl:latest
|
||||
FROM ubuntu:22.04
|
||||
|
||||
RUN apt-get update && apt-get install --no-install-recommends -y \
|
||||
autoconf \
|
||||
automake \
|
||||
ca-certificates \
|
||||
curl \
|
||||
libconfig-dev \
|
||||
libopus-dev \
|
||||
libsodium-dev \
|
||||
libtool \
|
||||
libvpx-dev \
|
||||
make \
|
||||
pkg-config \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
RUN groupadd -r -g 1000 builder \
|
||||
&& useradd -m --no-log-init -r -g builder -u 1000 builder
|
||||
USER builder
|
||||
|
||||
WORKDIR /home/builder
|
||||
|
||||
# Copy the sources and run the build.
|
||||
COPY --chown=builder:builder . /home/builder/c-toxcore/
|
||||
|
@ -1,13 +1,15 @@
|
||||
FROM toxchat/c-toxcore:sources AS src
|
||||
FROM ubuntu:22.04 AS build
|
||||
FROM ubuntu:20.04 AS build
|
||||
|
||||
RUN apt-get update && \
|
||||
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
|
||||
ca-certificates \
|
||||
clang \
|
||||
cmake \
|
||||
curl \
|
||||
gcc \
|
||||
git \
|
||||
golang \
|
||||
golang-1.18 \
|
||||
libconfig-dev \
|
||||
libgtest-dev \
|
||||
libopus-dev \
|
||||
@ -22,10 +24,16 @@ RUN apt-get update && \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& pip3 install --no-cache-dir gcovr
|
||||
RUN ["strip", "-g",\
|
||||
"/usr/lib/x86_64-linux-gnu/libgtest.a",\
|
||||
"/usr/lib/x86_64-linux-gnu/libgtest_main.a"]
|
||||
RUN ["curl", "-s", "https://codecov.io/bash", "-o", "/usr/local/bin/codecov"]
|
||||
RUN ["chmod", "+x", "/usr/local/bin/codecov"]
|
||||
|
||||
ENV CC=clang \
|
||||
CXX=clang++ \
|
||||
PYTHONUNBUFFERED=1
|
||||
PYTHONUNBUFFERED=1 \
|
||||
PATH=$PATH:/usr/lib/go-1.18/bin
|
||||
SHELL ["/bin/bash", "-c"]
|
||||
|
||||
WORKDIR /work
|
||||
@ -41,26 +49,27 @@ RUN source .github/scripts/flags-coverage.sh \
|
||||
-DENABLE_SHARED=OFF \
|
||||
-DMIN_LOGGER_LEVEL=TRACE \
|
||||
-DMUST_BUILD_TOXAV=ON \
|
||||
-DNON_HERMETIC_TESTS=ON \
|
||||
-DNON_HERMETIC_TESTS=OFF \
|
||||
-DSTRICT_ABI=ON \
|
||||
-DAUTOTEST=ON \
|
||||
-DPROXY_TEST=ON \
|
||||
-DUSE_IPV6=OFF \
|
||||
-DTEST_TIMEOUT_SECONDS=30 \
|
||||
-DTEST_TIMEOUT_SECONDS=40 \
|
||||
&& cmake --build _build --parallel 8 --target install
|
||||
|
||||
WORKDIR /work/_build
|
||||
RUN /work/proxy_server \
|
||||
& ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6
|
||||
RUN /work/other/proxy/proxy_server \
|
||||
& (ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6 || \
|
||||
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6)
|
||||
|
||||
WORKDIR /work/mallocfail
|
||||
RUN ["git", "clone", "--depth=1", "https://github.com/ralight/mallocfail", "/work/mallocfail"]
|
||||
COPY run_mallocfail /usr/local/bin/
|
||||
COPY syscall_funcs.c src/
|
||||
COPY other/docker/coverage/syscall_funcs.c src/
|
||||
RUN gcc -fPIC -shared -O2 -g3 -Wall -Ideps/uthash -Ideps/sha3 deps/*/*.c src/*.c -o mallocfail.so -ldl -lbacktrace \
|
||||
&& install mallocfail.so /usr/local/lib/mallocfail.so
|
||||
|
||||
WORKDIR /work/_build
|
||||
COPY other/docker/coverage/run_mallocfail /usr/local/bin/
|
||||
RUN ["run_mallocfail", "--ctest=2", "--jobs=8"]
|
||||
RUN ["gcovr", \
|
||||
"--sort-percentage", \
|
||||
@ -74,6 +83,4 @@ RUN ["gcovr", \
|
||||
"--exclude=(.+/)?other/", \
|
||||
"--exclude=(.+/)?testing/"]
|
||||
|
||||
FROM nginx:alpine
|
||||
COPY --from=build /work/_build/html/coverage_details.html /usr/share/nginx/html/index.html
|
||||
COPY --from=build /work/_build/html/ /usr/share/nginx/html/
|
||||
WORKDIR /work
|
||||
|
5
other/docker/coverage/Dockerfile.nginx
Normal file
5
other/docker/coverage/Dockerfile.nginx
Normal file
@ -0,0 +1,5 @@
|
||||
# vim:ft=dockerfile
|
||||
FROM toxchat/c-toxcore:coverage AS build
|
||||
FROM nginx:alpine
|
||||
COPY --from=build /work/_build/html/coverage_details.html /usr/share/nginx/html/index.html
|
||||
COPY --from=build /work/_build/html/ /usr/share/nginx/html/
|
@ -1,7 +1,9 @@
|
||||
#!/bin/sh
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -eux
|
||||
|
||||
read -a ci_env <<<"$(bash <(curl -s https://codecov.io/env))"
|
||||
|
||||
docker build -t toxchat/c-toxcore:sources -f other/docker/sources/Dockerfile .
|
||||
docker build -t toxchat/c-toxcore:coverage other/docker/coverage
|
||||
docker run --name toxcore-coverage --rm -it -p "28192:80" toxchat/c-toxcore:coverage
|
||||
docker build -t toxchat/c-toxcore:coverage -f other/docker/coverage/Dockerfile .
|
||||
docker run "${ci_env[@]}" -e CI=true --name toxcore-coverage --rm -t toxchat/c-toxcore:coverage /usr/local/bin/codecov -x "llvm-cov gcov"
|
||||
|
@ -39,8 +39,8 @@ _ENV = {
|
||||
}
|
||||
|
||||
|
||||
def run_mallocfail(tmpdir: str, timeout: float, exe: str,
|
||||
iteration: int) -> bool:
|
||||
def run_mallocfail(tmpdir: str, timeout: float, exe: str, iteration: int,
|
||||
keep_going: bool) -> bool:
|
||||
"""Run a program with mallocfail."""
|
||||
print(f"\x1b[1;33mmallocfail '{exe}' run #{iteration}\x1b[0m")
|
||||
hashes = os.path.join(tmpdir, _HASHES)
|
||||
@ -73,7 +73,8 @@ def run_mallocfail(tmpdir: str, timeout: float, exe: str,
|
||||
print(
|
||||
f"\x1b[1;32mProgram '{exe}' failed to handle OOM situation cleanly\x1b[0m"
|
||||
)
|
||||
raise Exception("Aborting test")
|
||||
if not keep_going:
|
||||
raise Exception("Aborting test")
|
||||
|
||||
return True
|
||||
|
||||
@ -95,7 +96,8 @@ def find_prog(name: str) -> Tuple[Optional[str], ...]:
|
||||
return path
|
||||
return None
|
||||
|
||||
return (attempt(f"./unit_{name}_test"), attempt(f"./auto_{name}_test"))
|
||||
return (attempt(f"./unit_{name}_test"),
|
||||
attempt(f"auto_tests/auto_{name}_test"))
|
||||
|
||||
|
||||
def parse_flags(args: List[str]) -> Tuple[Dict[str, str], List[str]]:
|
||||
@ -110,15 +112,19 @@ def parse_flags(args: List[str]) -> Tuple[Dict[str, str], List[str]]:
|
||||
return flags, exes
|
||||
|
||||
|
||||
def loop_mallocfail(tmpdir: str, timeout: float, exe: str) -> None:
|
||||
def loop_mallocfail(tmpdir: str,
|
||||
timeout: float,
|
||||
exe: str,
|
||||
keep_going: bool = False) -> None:
|
||||
i = 1
|
||||
while run_mallocfail(tmpdir, timeout, exe, i):
|
||||
while run_mallocfail(tmpdir, timeout, exe, i, keep_going):
|
||||
i += 1
|
||||
|
||||
|
||||
def isolated_mallocfail(timeout: int, exe: str) -> None:
|
||||
with tempfile.TemporaryDirectory(prefix="mallocfail") as tmpdir:
|
||||
print(f"\x1b[1;33mRunning for {exe} in isolated path {tmpdir}\x1b[0m")
|
||||
os.mkdir(os.path.join(tmpdir, "auto_tests"))
|
||||
shutil.copy(exe, os.path.join(tmpdir, exe))
|
||||
shutil.copy(_HASHES, os.path.join(tmpdir, _HASHES))
|
||||
loop_mallocfail(tmpdir, timeout, exe)
|
||||
@ -149,7 +155,7 @@ def main(args: List[str]) -> None:
|
||||
# such as llvm_gcov_init fail.
|
||||
if os.path.exists(_PRIMER):
|
||||
print(f"\x1b[1;33mPriming hashes with unit_util_test\x1b[0m")
|
||||
loop_mallocfail(".", timeout, _PRIMER)
|
||||
loop_mallocfail(".", timeout, _PRIMER, keep_going=True)
|
||||
|
||||
print(f"\x1b[1;33m--------------------------------\x1b[0m")
|
||||
print(f"\x1b[1;33mStarting mallocfail for {len(exes)} programs:\x1b[0m")
|
||||
|
8
other/docker/coverage/serve
Executable file
8
other/docker/coverage/serve
Executable file
@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eux
|
||||
|
||||
docker build -t toxchat/c-toxcore:sources -f other/docker/sources/Dockerfile .
|
||||
docker build -t toxchat/c-toxcore:coverage -f other/docker/coverage/Dockerfile .
|
||||
docker build -t toxchat/c-toxcore:coverage-nginx -f other/docker/coverage/Dockerfile.nginx other/docker/coverage
|
||||
docker run --name toxcore-coverage --rm -it -p "28192:80" toxchat/c-toxcore:coverage-nginx
|
30
other/docker/cppcheck/Dockerfile
Normal file
30
other/docker/cppcheck/Dockerfile
Normal file
@ -0,0 +1,30 @@
|
||||
FROM alpine:3.19.0
|
||||
|
||||
RUN ["apk", "add", "--no-cache", \
|
||||
"bash", \
|
||||
"cppcheck", \
|
||||
"findutils", \
|
||||
"libconfig-dev", \
|
||||
"libsodium-dev", \
|
||||
"libvpx-dev", \
|
||||
"linux-headers", \
|
||||
"make", \
|
||||
"opus-dev"]
|
||||
|
||||
COPY other/bootstrap_daemon/ /src/workspace/c-toxcore/other/bootstrap_daemon/
|
||||
COPY other/bootstrap_node_packets.* /src/workspace/c-toxcore/other/
|
||||
COPY other/fun/ /src/workspace/c-toxcore/other/fun/
|
||||
COPY auto_tests/check_compat.h /src/workspace/c-toxcore/auto_tests/
|
||||
COPY testing/ /src/workspace/c-toxcore/testing/
|
||||
COPY toxav/ /src/workspace/c-toxcore/toxav/
|
||||
COPY toxcore/ /src/workspace/c-toxcore/toxcore/
|
||||
COPY toxencryptsave/ /src/workspace/c-toxcore/toxencryptsave/
|
||||
COPY third_party/cmp/cmp.h /src/workspace/c-toxcore/third_party/cmp/
|
||||
COPY other/analysis/run-cppcheck \
|
||||
other/analysis/gen-file.sh \
|
||||
other/analysis/variants.sh \
|
||||
/src/workspace/c-toxcore/other/analysis/
|
||||
COPY other/docker/cppcheck/toxcore.cfg \
|
||||
/src/workspace/c-toxcore/other/docker/cppcheck/
|
||||
WORKDIR /src/workspace/c-toxcore
|
||||
RUN ["other/analysis/run-cppcheck"]
|
5
other/docker/cppcheck/run
Executable file
5
other/docker/cppcheck/run
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eux
|
||||
BUILD=cppcheck
|
||||
docker build -t "toxchat/c-toxcore:$BUILD" -f "other/docker/$BUILD/Dockerfile" .
|
117
other/docker/cppcheck/toxcore.cfg
Normal file
117
other/docker/cppcheck/toxcore.cfg
Normal file
@ -0,0 +1,117 @@
|
||||
<?xml version="1.0"?>
|
||||
<def format="2">
|
||||
<memory>
|
||||
<alloc init="false" buffer-size="malloc:2">mem_balloc</alloc>
|
||||
<alloc init="true" buffer-size="malloc:2">mem_alloc</alloc>
|
||||
<alloc init="true" buffer-size="calloc:2,3">mem_valloc</alloc>
|
||||
<realloc init="false" buffer-size="calloc:3,4">mem_vrealloc</realloc>
|
||||
<dealloc arg="2">mem_delete</dealloc>
|
||||
</memory>
|
||||
<resource>
|
||||
<alloc init="true">bin_pack_new</alloc>
|
||||
<dealloc arg="1">bin_pack_free</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">bin_unpack_new</alloc>
|
||||
<dealloc arg="1">bin_unpack_free</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">friendreq_new</alloc>
|
||||
<dealloc arg="1">friendreq_kill</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">logger_new</alloc>
|
||||
<dealloc arg="1">logger_kill</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">mono_time_new</alloc>
|
||||
<dealloc arg="1">mono_time_free</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">ping_array_new</alloc>
|
||||
<dealloc arg="1">ping_array_kill</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">ping_new</alloc>
|
||||
<dealloc arg="1">ping_kill</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">shared_key_cache_new</alloc>
|
||||
<dealloc arg="1">shared_key_cache_free</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">tox_dispatch_new</alloc>
|
||||
<dealloc arg="1">tox_dispatch_free</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">tox_new</alloc>
|
||||
<dealloc arg="1">tox_kill</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">tox_options_new</alloc>
|
||||
<dealloc arg="1">tox_options_free</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_announcements</alloc>
|
||||
<dealloc arg="1">kill_announcements</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_dht</alloc>
|
||||
<dealloc arg="1">kill_dht</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_dht_groupchats</alloc>
|
||||
<dealloc arg="1">kill_dht_groupchats</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_forwarding</alloc>
|
||||
<dealloc arg="1">kill_forwarding</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_friend_connections</alloc>
|
||||
<dealloc arg="1">kill_friend_connections</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_gca_list</alloc>
|
||||
<dealloc arg="1">kill_gca_list</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_groupchats</alloc>
|
||||
<dealloc arg="1">kill_groupchats</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_messenger</alloc>
|
||||
<dealloc arg="1">kill_messenger</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_net_crypto</alloc>
|
||||
<dealloc arg="1">kill_net_crypto</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_networking_ex</alloc>
|
||||
<alloc init="true">new_networking_no_udp</alloc>
|
||||
<dealloc arg="1">kill_networking</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_onion</alloc>
|
||||
<dealloc arg="1">kill_onion</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_onion_announce</alloc>
|
||||
<dealloc arg="1">kill_onion_announce</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_onion_client</alloc>
|
||||
<dealloc arg="1">kill_onion_client</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_tcp_connections</alloc>
|
||||
<dealloc arg="1">kill_tcp_connections</dealloc>
|
||||
</resource>
|
||||
<resource>
|
||||
<alloc init="true">new_tcp_server</alloc>
|
||||
<dealloc arg="1">kill_tcp_server</dealloc>
|
||||
</resource>
|
||||
</def>
|
||||
<!-- vim:ft=xml
|
||||
-->
|
15
other/docker/esp32/BUILD.bazel
Normal file
15
other/docker/esp32/BUILD.bazel
Normal file
@ -0,0 +1,15 @@
|
||||
load("@rules_cc//cc:defs.bzl", "cc_binary")
|
||||
|
||||
cc_binary(
|
||||
name = "host_main",
|
||||
testonly = 1,
|
||||
srcs = [
|
||||
"host_main.cc",
|
||||
"main/tox_main.cc",
|
||||
"main/tox_main.h",
|
||||
],
|
||||
deps = [
|
||||
"//c-toxcore/toxcore:tox",
|
||||
"//c-toxcore/toxcore:tox_events",
|
||||
],
|
||||
)
|
@ -1,48 +1,32 @@
|
||||
FROM toxchat/c-toxcore:sources AS src
|
||||
FROM ubuntu:18.04
|
||||
FROM mluis/qemu-esp32:latest
|
||||
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
|
||||
ENV IDF_TARGET=esp32
|
||||
|
||||
RUN apt-get update && \
|
||||
DEBIAN_FRONTEND="noninteractive" apt-get install -y --no-install-recommends \
|
||||
bison \
|
||||
ccache \
|
||||
cmake \
|
||||
flex \
|
||||
git \
|
||||
gperf \
|
||||
libncurses-dev \
|
||||
ninja-build \
|
||||
python \
|
||||
python-cryptography \
|
||||
python-future \
|
||||
python-pip \
|
||||
python-pyparsing \
|
||||
python-serial \
|
||||
python-setuptools \
|
||||
wget \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
WORKDIR /root/toxcore
|
||||
|
||||
ENV ESP32_TARBALL=xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0 \
|
||||
IDF_PATH="/root/esp/esp-idf" \
|
||||
PATH="/root/esp/esp-idf/tools:/root/esp/xtensa-esp32-elf/bin:$PATH"
|
||||
WORKDIR /root/esp
|
||||
RUN wget -q https://dl.espressif.com/dl/$ESP32_TARBALL.tar.gz \
|
||||
&& tar zxf $ESP32_TARBALL.tar.gz \
|
||||
&& rm -f $ESP32_TARBALL.tar.gz \
|
||||
&& git clone -b v3.3 --recursive --depth=1 --shallow-submodules https://github.com/espressif/esp-idf
|
||||
# Build an initial bootstrap hello world just to compile libsodium and other
|
||||
# system level dependencies.
|
||||
COPY other/docker/esp32/sdkconfig \
|
||||
other/docker/esp32/CMakeLists.txt \
|
||||
/root/toxcore/
|
||||
COPY other/docker/esp32/bootstrap/ \
|
||||
/root/toxcore/main/
|
||||
RUN . /root/esp/esp-idf/export.sh && idf.py build
|
||||
|
||||
# Build a hello world first, so the OS and libsodium etc. are compiled.
|
||||
WORKDIR /root/esp/toxcore
|
||||
COPY other/docker/esp32/CMakeLists.txt /root/esp/toxcore/
|
||||
COPY other/docker/esp32/hello/ /root/esp/toxcore/main/
|
||||
RUN idf.py build
|
||||
|
||||
# Then copy over the actual toxcore sources and build those.
|
||||
COPY --from=src /src/third_party/cmp/ /root/esp/toxcore/main/third_party/cmp/
|
||||
COPY --from=src /src/toxencryptsave/defines.h /root/esp/toxcore/main/toxencryptsave/
|
||||
COPY --from=src /src/toxcore/ /root/esp/toxcore/main/toxcore/
|
||||
COPY other/docker/esp32/toxcore/CMakeLists.txt /root/esp/toxcore/main/
|
||||
COPY other/docker/esp32/toxcore/toxcore_main.cc /root/esp/toxcore/main/other/docker/esp32/main/
|
||||
RUN idf.py build
|
||||
# Copy over toxcore sources and build those.
|
||||
COPY third_party/cmp/ /root/toxcore/main/third_party/cmp/
|
||||
COPY toxencryptsave/defines.h /root/toxcore/main/toxencryptsave/
|
||||
COPY toxcore/ /root/toxcore/main/toxcore/
|
||||
COPY other/docker/esp32/main/CMakeLists.txt \
|
||||
/root/toxcore/main/
|
||||
COPY other/docker/esp32/main/*.cc \
|
||||
other/docker/esp32/main/*.h \
|
||||
/root/toxcore/main/other/docker/esp32/main/
|
||||
RUN touch /root/toxcore/main/CMakeLists.txt \
|
||||
&& . /root/esp/esp-idf/export.sh && idf.py build
|
||||
RUN ls -lh build/toxcore.bin \
|
||||
&& shasum build/toxcore.bin
|
||||
&& sha512sum build/toxcore.bin
|
||||
RUN /root/flash.sh build/toxcore.bin
|
||||
|
||||
COPY other/docker/esp32/qemu-test /root/toxcore/
|
||||
RUN ["/root/toxcore/qemu-test"]
|
||||
|
4
other/docker/esp32/bootstrap/CMakeLists.txt
Normal file
4
other/docker/esp32/bootstrap/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
||||
idf_component_register(
|
||||
SRCS hello_main.cc
|
||||
INCLUDE_DIRS "."
|
||||
REQUIRES esp_netif lwip)
|
4
other/docker/esp32/bootstrap/hello_main.cc
Normal file
4
other/docker/esp32/bootstrap/hello_main.cc
Normal file
@ -0,0 +1,4 @@
|
||||
#include <stdio.h>
|
||||
|
||||
// Bootstrap main. Only writes hello world. See ../main/ for the real thing.
|
||||
extern "C" void app_main(void) { printf("Hello world!\n"); }
|
2
other/docker/esp32/bootstrap/idf_component.yml
Normal file
2
other/docker/esp32/bootstrap/idf_component.yml
Normal file
@ -0,0 +1,2 @@
|
||||
dependencies:
|
||||
espressif/libsodium: "==1.0.20"
|
@ -1,4 +0,0 @@
|
||||
set(COMPONENT_SRCS "hello_main.c")
|
||||
set(COMPONENT_ADD_INCLUDEDIRS "")
|
||||
|
||||
register_component()
|
@ -1,6 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
printf("Hello world!\n");
|
||||
}
|
3
other/docker/esp32/host_main.cc
Normal file
3
other/docker/esp32/host_main.cc
Normal file
@ -0,0 +1,3 @@
|
||||
#include "main/tox_main.h"
|
||||
|
||||
int main() { tox_main(); }
|
16
other/docker/esp32/main/CMakeLists.txt
Normal file
16
other/docker/esp32/main/CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-missing-field-initializers -Wno-format -DMIN_LOGGER_LEVEL=LOGGER_LEVEL_TRACE")
|
||||
|
||||
file(GLOB toxcore_SRCS "toxcore/*.[ch]" "toxcore/*/*.[ch]")
|
||||
set(COMPONENT_SRCS
|
||||
${toxcore_SRCS}
|
||||
other/docker/esp32/main/app_main.cc
|
||||
other/docker/esp32/main/tox_main.cc
|
||||
other/docker/esp32/main/tox_main.h
|
||||
third_party/cmp/cmp.c
|
||||
third_party/cmp/cmp.h
|
||||
toxencryptsave/defines.h)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${COMPONENT_SRCS}
|
||||
INCLUDE_DIRS "."
|
||||
REQUIRES esp_eth esp_netif lwip)
|
73
other/docker/esp32/main/app_main.cc
Normal file
73
other/docker/esp32/main/app_main.cc
Normal file
@ -0,0 +1,73 @@
|
||||
#include <esp_eth.h>
|
||||
#include <esp_event.h>
|
||||
#include <esp_log.h>
|
||||
#include <esp_netif.h>
|
||||
#include <esp_netif_sntp.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "tox_main.h"
|
||||
|
||||
static const char *MAIN_TAG = "app_main";
|
||||
static constexpr int NTP_TIMEOUT = 60; // 1 minute
|
||||
|
||||
static esp_eth_handle_t eth_handle = nullptr;
|
||||
static esp_netif_t *eth_netif = nullptr;
|
||||
|
||||
static void event_handler(
|
||||
void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
|
||||
{
|
||||
if (event_base == ETH_EVENT) {
|
||||
if (event_id == ETHERNET_EVENT_START) {
|
||||
return;
|
||||
}
|
||||
if (event_id == ETHERNET_EVENT_STOP) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (event_base == IP_EVENT) {
|
||||
if (event_id == IP_EVENT_ETH_GOT_IP) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void register_ethernet(void)
|
||||
{
|
||||
ESP_ERROR_CHECK(esp_netif_init());
|
||||
ESP_ERROR_CHECK(esp_event_loop_create_default());
|
||||
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH();
|
||||
eth_netif = esp_netif_new(&cfg);
|
||||
|
||||
eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
|
||||
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
|
||||
esp_eth_mac_t *mac = esp_eth_mac_new_openeth(&mac_config);
|
||||
|
||||
esp_eth_phy_t *phy = esp_eth_phy_new_dp83848(&phy_config);
|
||||
|
||||
esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
|
||||
ESP_ERROR_CHECK(esp_eth_driver_install(&config, ð_handle));
|
||||
ESP_ERROR_CHECK(esp_netif_attach(eth_netif, esp_eth_new_netif_glue(eth_handle)));
|
||||
ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, &event_handler, NULL));
|
||||
ESP_ERROR_CHECK(
|
||||
esp_event_handler_register(IP_EVENT, IP_EVENT_ETH_GOT_IP, &event_handler, NULL));
|
||||
ESP_ERROR_CHECK(esp_eth_start(eth_handle));
|
||||
}
|
||||
|
||||
// Does all the esp32-specific init before running generic tox code.
|
||||
extern "C" void app_main(void)
|
||||
{
|
||||
register_ethernet();
|
||||
|
||||
esp_sntp_config_t config = ESP_NETIF_SNTP_DEFAULT_CONFIG("pool.ntp.org");
|
||||
ESP_ERROR_CHECK(esp_netif_sntp_init(&config));
|
||||
|
||||
if (esp_netif_sntp_sync_wait(pdMS_TO_TICKS(NTP_TIMEOUT * 1000)) != ESP_OK) {
|
||||
ESP_LOGE(MAIN_TAG, "failed to update system time within %ds timeout", NTP_TIMEOUT);
|
||||
return;
|
||||
}
|
||||
|
||||
ESP_LOGI(MAIN_TAG, "time is updated: %lld", time(nullptr));
|
||||
|
||||
tox_main();
|
||||
}
|
98
other/docker/esp32/main/tox_main.cc
Normal file
98
other/docker/esp32/main/tox_main.cc
Normal file
@ -0,0 +1,98 @@
|
||||
#include "../main/tox_main.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "../../../../toxcore/ccompat.h"
|
||||
#include "../../../../toxcore/tox.h"
|
||||
#include "../../../../toxcore/tox_events.h"
|
||||
|
||||
static const char *color(int index)
|
||||
{
|
||||
switch (index) {
|
||||
case 0:
|
||||
return "\033"
|
||||
"[35m";
|
||||
case 1:
|
||||
return "\033"
|
||||
"[36m";
|
||||
}
|
||||
|
||||
return "\033"
|
||||
"[0m";
|
||||
}
|
||||
|
||||
static tox_log_cb log_handler;
|
||||
static void log_handler(Tox *tox, Tox_Log_Level level, const char *file, uint32_t line,
|
||||
const char *func, const char *msg, void *user_data)
|
||||
{
|
||||
const int *index = static_cast<const int *>(user_data);
|
||||
const uint16_t udp_port = tox_self_get_udp_port(tox, nullptr);
|
||||
printf("%s#%d (:%d) [%c] %s:%u(%s): %s\n", color(*index), *index, udp_port,
|
||||
tox_log_level_to_string(level)[0], file, static_cast<unsigned int>(line), func, msg);
|
||||
}
|
||||
|
||||
using Tox_Options_Ptr = std::unique_ptr<Tox_Options, void (*)(Tox_Options *)>;
|
||||
using Tox_Ptr = std::unique_ptr<Tox, void (*)(Tox *)>;
|
||||
|
||||
void tox_main()
|
||||
{
|
||||
printf("Hello Tox!\n");
|
||||
|
||||
Tox_Options_Ptr opts(tox_options_new(nullptr), tox_options_free);
|
||||
assert(opts != nullptr);
|
||||
|
||||
tox_options_set_ipv6_enabled(opts.get(), false);
|
||||
tox_options_set_local_discovery_enabled(opts.get(), false);
|
||||
|
||||
tox_options_set_log_callback(opts.get(), log_handler);
|
||||
|
||||
Tox_Err_New err;
|
||||
|
||||
int index[] = {0, 1};
|
||||
|
||||
tox_options_set_log_user_data(opts.get(), &index[0]);
|
||||
Tox_Ptr tox0(tox_new(opts.get(), &err), tox_kill);
|
||||
printf("tox_new(#0): %p\n", static_cast<void *>(tox0.get()));
|
||||
|
||||
if (err != TOX_ERR_NEW_OK) {
|
||||
printf("tox_new(#0): %s\n", tox_err_new_to_string(err));
|
||||
return;
|
||||
}
|
||||
|
||||
tox_options_set_log_user_data(opts.get(), &index[1]);
|
||||
Tox_Ptr tox1(tox_new(opts.get(), &err), tox_kill);
|
||||
printf("tox_new(#1): %p\n", static_cast<void *>(tox0.get()));
|
||||
|
||||
if (err != TOX_ERR_NEW_OK) {
|
||||
printf("tox_new(#1): %s\n", tox_err_new_to_string(err));
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t pk[TOX_PUBLIC_KEY_SIZE];
|
||||
tox_self_get_dht_id(tox0.get(), pk);
|
||||
tox_bootstrap(tox1.get(), "localhost", tox_self_get_udp_port(tox0.get(), nullptr), pk, nullptr);
|
||||
|
||||
#if 0
|
||||
tox_self_get_public_key(tox0.get(), pk);
|
||||
tox_friend_add_norequest(tox1.get(), pk, nullptr);
|
||||
|
||||
tox_self_get_public_key(tox1.get(), pk);
|
||||
tox_friend_add_norequest(tox0.get(), pk, nullptr);
|
||||
#endif
|
||||
|
||||
printf("bootstrapping and connecting 2 toxes\n");
|
||||
|
||||
while (tox_self_get_connection_status(tox1.get()) == TOX_CONNECTION_NONE
|
||||
|| tox_self_get_connection_status(tox0.get()) == TOX_CONNECTION_NONE) {
|
||||
tox_events_free(tox_events_iterate(tox0.get(), true, nullptr));
|
||||
tox_events_free(tox_events_iterate(tox1.get(), true, nullptr));
|
||||
|
||||
usleep(tox_iteration_interval(tox0.get()) * 1000);
|
||||
usleep(250); // a bit less noise in the log
|
||||
}
|
||||
}
|
6
other/docker/esp32/main/tox_main.h
Normal file
6
other/docker/esp32/main/tox_main.h
Normal file
@ -0,0 +1,6 @@
|
||||
#ifndef TOX_MAIN_H
|
||||
#define TOX_MAIN_H
|
||||
|
||||
void tox_main();
|
||||
|
||||
#endif // TOX_MAIN_H
|
17
other/docker/esp32/qemu-test
Executable file
17
other/docker/esp32/qemu-test
Executable file
@ -0,0 +1,17 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -eu
|
||||
|
||||
qemu-system-xtensa \
|
||||
-nographic \
|
||||
-M esp32 \
|
||||
-m 4 \
|
||||
-drive file=flash.bin,if=mtd,format=raw \
|
||||
-nic user,model=open_eth,hostfwd=tcp::80-:80 \
|
||||
-s |
|
||||
tee qemu.log &
|
||||
|
||||
echo "Waiting for program to complete"
|
||||
while ! grep 'Returned from app_main' qemu.log >/dev/null; do
|
||||
sleep 1
|
||||
done
|
@ -1,4 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
docker build -t toxchat/c-toxcore:sources -f other/docker/sources/Dockerfile .
|
||||
docker build -t toxchat/c-toxcore:esp32 -f other/docker/esp32/Dockerfile .
|
||||
|
5
other/docker/esp32/run-host
Executable file
5
other/docker/esp32/run-host
Executable file
@ -0,0 +1,5 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eux
|
||||
|
||||
bazel run //c-toxcore/other/docker/esp32:host_main
|
1937
other/docker/esp32/sdkconfig
Normal file
1937
other/docker/esp32/sdkconfig
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,12 +0,0 @@
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-missing-field-initializers")
|
||||
|
||||
file(GLOB toxcore_SRCS "toxcore/*.[ch]" "toxcore/*/*.[ch]")
|
||||
set(COMPONENT_SRCS
|
||||
${toxcore_SRCS}
|
||||
other/docker/esp32/main/toxcore_main.cc
|
||||
third_party/cmp/cmp.c
|
||||
third_party/cmp/cmp.h
|
||||
toxencryptsave/defines.h)
|
||||
set(COMPONENT_ADD_INCLUDEDIRS "")
|
||||
|
||||
register_component()
|
@ -1,14 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../../../../toxcore/ccompat.h"
|
||||
#include "../../../../toxcore/tox.h"
|
||||
#include "../../../../toxcore/tox_events.h"
|
||||
|
||||
extern "C" void app_main(void)
|
||||
{
|
||||
printf("Hello Tox!\n");
|
||||
|
||||
Tox *tox = tox_new(nullptr, nullptr);
|
||||
tox_events_free(tox_events_iterate(tox, true, nullptr));
|
||||
tox_kill(tox);
|
||||
}
|
@ -39,7 +39,7 @@ RUN tcc \
|
||||
|
||||
COPY other/make_single_file /work/other/
|
||||
RUN \
|
||||
other/make_single_file \
|
||||
other/make_single_file -core \
|
||||
auto_tests/auto_test_support.c \
|
||||
auto_tests/send_message_test.c \
|
||||
testing/misc_tools.c | \
|
||||
@ -47,5 +47,17 @@ RUN \
|
||||
-o send_message_test \
|
||||
-Wall -Werror \
|
||||
-bench -g \
|
||||
$(pkg-config --cflags --libs libsodium opus vpx) \
|
||||
$(pkg-config --cflags --libs libsodium) \
|
||||
&& ./send_message_test | grep 'tox clients connected'
|
||||
|
||||
RUN \
|
||||
other/make_single_file \
|
||||
auto_tests/auto_test_support.c \
|
||||
auto_tests/toxav_basic_test.c \
|
||||
testing/misc_tools.c | \
|
||||
tcc - \
|
||||
-o toxav_basic_test \
|
||||
-Wall -Werror \
|
||||
-bench -g \
|
||||
$(pkg-config --cflags --libs libsodium opus vpx) \
|
||||
&& ./toxav_basic_test | grep 'Test successful'
|
||||
|
12
other/event_tooling/Dockerfile
Normal file
12
other/event_tooling/Dockerfile
Normal file
@ -0,0 +1,12 @@
|
||||
FROM ubuntu:22.04
|
||||
|
||||
RUN apt-get update && apt-get install --no-install-recommends -y \
|
||||
build-essential \
|
||||
ca-certificates \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
WORKDIR /src
|
||||
COPY generate_event_c.cpp /src/
|
||||
RUN ["g++", "generate_event_c.cpp", "-o", "generate_event_c"]
|
||||
CMD ["./generate_event_c"]
|
@ -80,27 +80,27 @@ std::string bin_unpack_name_from_type(const std::string& type) {
|
||||
} else if (type == "bool") {
|
||||
return "bin_unpack_bool";
|
||||
} else if (type == "Tox_User_Status") {
|
||||
return "tox_unpack_user_status";
|
||||
return "tox_user_status_unpack";
|
||||
} else if (type == "Tox_Conference_Type") {
|
||||
return "tox_unpack_conference_type";
|
||||
return "tox_conference_type_unpack";
|
||||
} else if (type == "Tox_Message_Type") {
|
||||
return "tox_unpack_message_type";
|
||||
return "tox_message_type_unpack";
|
||||
} else if (type == "Tox_File_Control") {
|
||||
return "tox_unpack_file_control";
|
||||
return "tox_file_control_unpack";
|
||||
} else if (type == "Tox_Connection") {
|
||||
return "tox_unpack_connection";
|
||||
return "tox_connection_unpack";
|
||||
} else if (type == "Tox_Group_Privacy_State") {
|
||||
return "tox_unpack_group_privacy_state";
|
||||
return "tox_group_privacy_state_unpack";
|
||||
} else if (type == "Tox_Group_Voice_State") {
|
||||
return "tox_unpack_group_voice_state";
|
||||
return "tox_group_voice_state_unpack";
|
||||
} else if (type == "Tox_Group_Topic_Lock") {
|
||||
return "tox_unpack_group_topic_lock";
|
||||
return "tox_group_topic_lock_unpack";
|
||||
} else if (type == "Tox_Group_Join_Fail") {
|
||||
return "tox_unpack_group_join_fail";
|
||||
return "tox_group_join_fail_unpack";
|
||||
} else if (type == "Tox_Group_Mod_Event") {
|
||||
return "tox_unpack_group_mod_event";
|
||||
return "tox_group_mod_event_unpack";
|
||||
} else if (type == "Tox_Group_Exit_Type") {
|
||||
return "tox_unpack_group_exit_type";
|
||||
return "tox_group_exit_type_unpack";
|
||||
} else {
|
||||
std::cerr << "unknown type " << type << "\n";
|
||||
exit(1);
|
||||
@ -109,7 +109,7 @@ std::string bin_unpack_name_from_type(const std::string& type) {
|
||||
}
|
||||
}
|
||||
|
||||
void generate_event_impl(const std::string& event_name, std::vector<EventType> event_types) {
|
||||
void generate_event_impl(const std::string& event_name, const std::vector<EventType>& event_types) {
|
||||
const std::string event_name_l = str_tolower(event_name);
|
||||
std::string file_name = output_folder + "/" + event_name_l + ".c";
|
||||
|
||||
@ -164,35 +164,6 @@ void generate_event_impl(const std::string& event_name, std::vector<EventType> e
|
||||
}
|
||||
f << "};\n\n";
|
||||
|
||||
// gen contruct
|
||||
f << "non_null()\n";
|
||||
f << "static void tox_event_" << event_name_l << "_construct(Tox_Event_" << event_name << " *" << event_name_l << ")\n{\n";
|
||||
// TODO: initialize all members properly
|
||||
// TODO: check if _NONE is universal
|
||||
// str_toupper(
|
||||
f << " *" << event_name_l << " = (Tox_Event_" << event_name << ") {\n 0\n };\n}\n";
|
||||
|
||||
// gen destruct
|
||||
f << "non_null()\n";
|
||||
f << "static void tox_event_" << event_name_l << "_destruct(Tox_Event_" << event_name << " *" << event_name_l << ")\n{\n";
|
||||
size_t data_count = 0;
|
||||
for (const auto& t : event_types) {
|
||||
std::visit(
|
||||
overloaded{
|
||||
[&](const EventTypeTrivial&) {},
|
||||
[&](const EventTypeByteRange& t) {
|
||||
f << " free(" << event_name_l << "->" << t.name_data << ");\n";
|
||||
data_count++;
|
||||
}
|
||||
},
|
||||
t
|
||||
);
|
||||
}
|
||||
if (data_count == 0) {
|
||||
f << " return;\n";
|
||||
}
|
||||
f << "}\n\n";
|
||||
|
||||
// gen setters and getters
|
||||
for (const auto& t : event_types) {
|
||||
// setter
|
||||
@ -258,7 +229,7 @@ void generate_event_impl(const std::string& event_name, std::vector<EventType> e
|
||||
},
|
||||
[&](const EventTypeByteRange& t) {
|
||||
//f << "non_null()\n"; // TODO: is this missing in the original?
|
||||
f << "size_t tox_event_" << event_name_l << "_get_" << t.name_length;
|
||||
f << "uint32_t tox_event_" << event_name_l << "_get_" << t.name_length;
|
||||
f << "(const Tox_Event_" << event_name << " *" << event_name_l << ")\n";
|
||||
f << "{\n assert(" << event_name_l << " != nullptr);\n";
|
||||
f << " return " << event_name_l << "->" << t.name_length << ";\n}\n";
|
||||
@ -272,15 +243,45 @@ void generate_event_impl(const std::string& event_name, std::vector<EventType> e
|
||||
);
|
||||
}
|
||||
|
||||
// pack
|
||||
|
||||
// gen contruct
|
||||
f << "non_null()\n";
|
||||
f << "static bool tox_event_" << event_name_l << "_pack(\n";
|
||||
f << "static void tox_event_" << event_name_l << "_construct(Tox_Event_" << event_name << " *" << event_name_l << ")\n{\n";
|
||||
// TODO: initialize all members properly
|
||||
// TODO: check if _NONE is universal
|
||||
// str_toupper(
|
||||
f << " *" << event_name_l << " = (Tox_Event_" << event_name << ") {\n 0\n };\n}\n";
|
||||
|
||||
// gen destruct
|
||||
f << "non_null()\n";
|
||||
f << "static void tox_event_" << event_name_l << "_destruct(Tox_Event_" << event_name << " *" << event_name_l << ", const Memory *mem)\n{\n";
|
||||
size_t data_count = 0;
|
||||
for (const auto& t : event_types) {
|
||||
std::visit(
|
||||
overloaded{
|
||||
[&](const EventTypeTrivial&) {},
|
||||
[&](const EventTypeByteRange& t) {
|
||||
f << " free(" << event_name_l << "->" << t.name_data << ");\n";
|
||||
//f << " mem->funcs->free(mem->obj, " << event_name_l << "->" << t.name_data << ");\n";
|
||||
data_count++;
|
||||
}
|
||||
},
|
||||
t
|
||||
);
|
||||
}
|
||||
if (data_count == 0) {
|
||||
f << " return;\n";
|
||||
}
|
||||
f << "}\n\n";
|
||||
|
||||
// pack
|
||||
f << "bool tox_event_" << event_name_l << "_pack(\n";
|
||||
f << " const Tox_Event_" << event_name << " *event, Bin_Pack *bp)\n{\n";
|
||||
f << " assert(event != nullptr);\n";
|
||||
f << " return bin_pack_array(bp, 2)\n";
|
||||
f << " && bin_pack_u32(bp, TOX_EVENT_" << str_toupper(event_name) << ")\n";
|
||||
f << " && bin_pack_u32(bp, TOX_EVENT_" << str_toupper(event_name) << ")";
|
||||
if (event_types.size() > 1) {
|
||||
f << " && bin_pack_array(bp, " << event_types.size() << ")";
|
||||
f << "\n && bin_pack_array(bp, " << event_types.size() << ")";
|
||||
}
|
||||
|
||||
for (const auto& t : event_types) {
|
||||
@ -302,7 +303,7 @@ void generate_event_impl(const std::string& event_name, std::vector<EventType> e
|
||||
|
||||
// unpack
|
||||
f << "non_null()\n";
|
||||
f << "static bool tox_event_" << event_name_l << "_unpack(\n";
|
||||
f << "static bool tox_event_" << event_name_l << "_unpack_into(\n";
|
||||
f << " Tox_Event_" << event_name << " *event, Bin_Unpack *bu)\n{\n";
|
||||
f << " assert(event != nullptr);\n";
|
||||
if (event_types.size() > 1) {
|
||||
@ -335,71 +336,82 @@ void generate_event_impl(const std::string& event_name, std::vector<EventType> e
|
||||
f << R"(
|
||||
/*****************************************************
|
||||
*
|
||||
* :: add/clear/get
|
||||
* :: new/free/add/get/size/unpack
|
||||
*
|
||||
*****************************************************/
|
||||
|
||||
|
||||
)";
|
||||
|
||||
f << "const Tox_Event_" << event_name << " *tox_event_get_" << event_name_l << "(const Tox_Event *event)\n{\n";
|
||||
f << " return event->type == TOX_EVENT_" << str_toupper(event_name) << " ? event->data." << event_name_l << " : nullptr;\n}\n\n";
|
||||
|
||||
// new
|
||||
f << "Tox_Event_" << event_name << " *tox_event_" << event_name_l << "_new(const Memory *mem)\n{\n";
|
||||
f << " Tox_Event_" << event_name << " *const " << event_name_l << " =\n";
|
||||
f << " (Tox_Event_" << event_name << " *)mem_alloc(mem, sizeof(Tox_Event_" << event_name << "));\n\n";
|
||||
f << " if (" << event_name_l << " == nullptr) {\n return nullptr;\n }\n\n";
|
||||
f << " tox_event_" << event_name_l << "_construct(" << event_name_l << ");\n";
|
||||
f << " return " << event_name_l << ";\n}\n\n";
|
||||
|
||||
// free
|
||||
f << "void tox_event_" << event_name_l << "_free(Tox_Event_" << event_name << " *" << event_name_l << ", const Memory *mem)\n{\n";
|
||||
f << " if (" << event_name_l << " != nullptr) {\n";
|
||||
f << " tox_event_" << event_name_l << "_destruct(" << event_name_l << ", mem);\n }\n";
|
||||
f << " mem_delete(mem, " << event_name_l << ");\n}\n\n";
|
||||
|
||||
// add
|
||||
f << "non_null()\n";
|
||||
f << "static Tox_Event_" << event_name << " *tox_events_add_" << event_name_l << "(Tox_Events *events)\n{\n";
|
||||
f << " if (events->" << event_name_l << "_size == UINT32_MAX) {\n";
|
||||
f << "static Tox_Event_" << event_name << " *tox_events_add_" << event_name_l << "(Tox_Events *events, const Memory *mem)\n{\n";
|
||||
f << " Tox_Event_" << event_name << " *const " << event_name_l << " = tox_event_" << event_name_l << "_new(mem);\n\n";
|
||||
f << " if (" << event_name_l << " == nullptr) {\n";
|
||||
f << " return nullptr;\n }\n\n";
|
||||
f << " if (events->" << event_name_l << "_size == events->" << event_name_l << "_capacity) {\n";
|
||||
f << " const uint32_t new_" << event_name_l << "_capacity = events->" << event_name_l << "_capacity * 2 + 1;\n";
|
||||
|
||||
f << " Tox_Event_" << event_name << " *new_" << event_name_l << " = (Tox_Event_" << event_name << " *)\n";
|
||||
f << " realloc(\n";
|
||||
|
||||
f << " events->" << event_name_l << ",\n";
|
||||
f << " new_" << event_name_l << "_capacity * sizeof(Tox_Event_" << event_name << "));\n\n";
|
||||
f << " if (new_" << event_name_l << " == nullptr) {\n return nullptr;\n }\n\n";
|
||||
f << " events->" << event_name_l << " = new_" << event_name_l << ";\n";
|
||||
f << " events->" << event_name_l << "_capacity = new_" << event_name_l << "_capacity;\n";
|
||||
f << " }\n\n";
|
||||
f << " Tox_Event_" << event_name << " *const " << event_name_l << " =\n";
|
||||
f << " &events->" << event_name_l << "[events->" << event_name_l << "_size];\n";
|
||||
f << " tox_event_" << event_name_l << "_construct(" << event_name_l << ");\n";
|
||||
f << " ++events->" << event_name_l << "_size;\n";
|
||||
f << " Tox_Event event;\n";
|
||||
f << " event.type = TOX_EVENT_" << str_toupper(event_name) << ";\n";
|
||||
f << " event.data." << event_name_l << " = " << event_name_l << ";\n\n";
|
||||
f << " tox_events_add(events, &event);\n";
|
||||
f << " return " << event_name_l << ";\n}\n\n";
|
||||
|
||||
// clear
|
||||
f << "void tox_events_clear_" << event_name_l << "(Tox_Events *events)\n{\n";
|
||||
f << " if (events == nullptr) {\n return;\n }\n\n";
|
||||
f << " for (uint32_t i = 0; i < events->" << event_name_l << "_size; ++i) {\n";
|
||||
f << " tox_event_" << event_name_l << "_destruct(&events->" << event_name_l << "[i]);\n }\n\n";
|
||||
f << " free(events->" << event_name_l << ");\n";
|
||||
f << " events->" << event_name_l << " = nullptr;\n";
|
||||
f << " events->" << event_name_l << "_size = 0;\n";
|
||||
f << " events->" << event_name_l << "_capacity = 0;\n";
|
||||
f << "}\n\n";
|
||||
|
||||
// get size
|
||||
f << "uint32_t tox_events_get_" << event_name_l << "_size(const Tox_Events *events)\n{\n";
|
||||
f << " if (events == nullptr) {\n return 0;\n }\n\n";
|
||||
f << " return events->" << event_name_l << "_size;\n}\n\n";
|
||||
|
||||
// get
|
||||
f << "const Tox_Event_" << event_name << " *tox_events_get_" << event_name_l << "(const Tox_Events *events, uint32_t index)\n{\n";
|
||||
f << " assert(index < events->" << event_name_l << "_size);\n";
|
||||
f << " assert(events->" << event_name_l << " != nullptr);\n";
|
||||
f << " return &events->" << event_name_l << "[index];\n}\n\n";
|
||||
|
||||
// aux pack
|
||||
f << "bool tox_events_pack_" << event_name_l << "(const Tox_Events *events, Bin_Pack *bp)\n{\n";
|
||||
f << " const uint32_t size = tox_events_get_" << event_name_l << "_size(events);\n\n";
|
||||
f << " uint32_t " << event_name_l << "_index = 0;\n";
|
||||
f << " const uint32_t size = tox_events_get_size(events);\n\n";
|
||||
f << " for (uint32_t i = 0; i < size; ++i) {\n";
|
||||
f << " if (!tox_event_" << event_name_l << "_pack(tox_events_get_" << event_name_l << "(events, i), bp)) {\n";
|
||||
f << " return false;\n }\n }\n";
|
||||
f << " return true;\n}\n\n";
|
||||
f << " if (" << event_name_l << "_index > index) {\n";
|
||||
f << " return nullptr;\n }\n\n";
|
||||
f << " if (events->events[i].type == TOX_EVENT_" << str_toupper(event_name) << ") {\n";
|
||||
f << " const Tox_Event_" << event_name << " *" << event_name_l << " = events->events[i].data." << event_name_l << ";\n";
|
||||
f << " if (" << event_name_l << "_index == index) {\n";
|
||||
f << " return " << event_name_l << ";\n }\n";
|
||||
f << " ++" << event_name_l << "_index;\n }\n }\n\n return nullptr;\n}\n\n";
|
||||
|
||||
// get size
|
||||
f << "uint32_t tox_events_get_" << event_name_l << "_size(const Tox_Events *events)\n{\n";
|
||||
f << " uint32_t " << event_name_l << "_size = 0;\n";
|
||||
f << " const uint32_t size = tox_events_get_size(events);\n\n";
|
||||
f << " for (uint32_t i = 0; i < size; ++i) {\n";
|
||||
f << " if (events->events[i].type == TOX_EVENT_" << str_toupper(event_name) << ") {\n";
|
||||
f << " ++" << event_name_l << "_size;\n }\n }\n\n";
|
||||
f << " return " << event_name_l << "_size;\n}\n\n";
|
||||
|
||||
// unpack
|
||||
f << "bool tox_event_" << event_name_l << "_unpack(\n";
|
||||
f << " Tox_Event_" << event_name << " **event, Bin_Unpack *bu, const Memory *mem)\n{\n";
|
||||
f << " assert(event != nullptr);\n";
|
||||
f << " *event = tox_event_" << event_name_l << "_new(mem);\n\n";
|
||||
f << " if (*event == nullptr) {\n return false;\n }\n\n";
|
||||
f << " return tox_event_" << event_name_l << "_unpack_into(*event, bu);\n}\n\n";
|
||||
|
||||
// alloc
|
||||
f << "non_null()\n";
|
||||
f << "static Tox_Event_" << event_name << " *tox_event_" << event_name_l << "_alloc(void *user_data)\n{\n";
|
||||
f << " Tox_Events_State *state = tox_events_alloc(user_data);\n";
|
||||
f << " assert(state != nullptr);\n\n";
|
||||
f << " if (state->events == nullptr) {\n return nullptr;\n }\n\n";
|
||||
f << " Tox_Event_" << event_name << " *" << event_name_l << " = tox_events_add_" << event_name_l << "(state->events, state->mem);\n\n";
|
||||
f << " if (" << event_name_l << " == nullptr) {\n";
|
||||
f << " state->error = TOX_ERR_EVENTS_ITERATE_MALLOC;\n return nullptr;\n }\n\n";
|
||||
f << " return " << event_name_l << ";\n}\n\n";
|
||||
|
||||
// aux unpack
|
||||
f << "bool tox_events_unpack_" << event_name_l << "(Tox_Events *events, Bin_Unpack *bu)\n{\n";
|
||||
f << " Tox_Event_" << event_name << " *event = tox_events_add_" << event_name_l << "(events);\n\n";
|
||||
f << " if (event == nullptr) {\n return false;\n }\n\n";
|
||||
f << " return tox_event_" << event_name_l << "_unpack(event, bu);\n}\n\n";
|
||||
|
||||
f << R"(
|
||||
/*****************************************************
|
||||
@ -427,12 +439,8 @@ void generate_event_impl(const std::string& event_name, std::vector<EventType> e
|
||||
}
|
||||
|
||||
f << ",\n void *user_data)\n{\n";
|
||||
f << " Tox_Events_State *state = tox_events_alloc(user_data);\n";
|
||||
f << " assert(state != nullptr);\n\n";
|
||||
f << " if (state->events == nullptr) {\n return;\n }\n\n";
|
||||
f << " Tox_Event_" << event_name << " *" << event_name_l << " = tox_events_add_" << event_name_l << "(state->events);\n\n";
|
||||
f << " if (" << event_name_l << " == nullptr) {\n";
|
||||
f << " state->error = TOX_ERR_EVENTS_ITERATE_MALLOC;\n return;\n }\n\n";
|
||||
f << " Tox_Event_" << event_name << " *" << event_name_l << " = tox_event_" << event_name_l << "_alloc(user_data);\n\n";
|
||||
f << " if (" << event_name_l << " == nullptr) {\n return;\n }\n\n";
|
||||
|
||||
for (const auto& t : event_types) {
|
||||
std::visit(
|
||||
@ -465,7 +473,7 @@ int main(int argc, char** argv) {
|
||||
{
|
||||
EventTypeTrivial{"uint32_t", "friend_number"},
|
||||
EventTypeTrivial{"Tox_Conference_Type", "type"},
|
||||
EventTypeByteRange{"cookie", "cookie_length", "length"}, // the later two are idealy the same
|
||||
EventTypeByteRange{"cookie", "cookie_length", "length"}, // the latter two are ideally the same
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -474,7 +482,7 @@ int main(int argc, char** argv) {
|
||||
EventTypeTrivial{"uint32_t", "conference_number"},
|
||||
EventTypeTrivial{"uint32_t", "peer_number"},
|
||||
EventTypeTrivial{"Tox_Message_Type", "type"},
|
||||
EventTypeByteRange{"message", "message_length", "length"}, // the later two are idealy the same
|
||||
EventTypeByteRange{"message", "message_length", "length"}, // the latter two are ideally the same
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -488,7 +496,7 @@ int main(int argc, char** argv) {
|
||||
{
|
||||
EventTypeTrivial{"uint32_t", "conference_number"},
|
||||
EventTypeTrivial{"uint32_t", "peer_number"},
|
||||
EventTypeByteRange{"name", "name_length", "length"}, // the later two are idealy the same
|
||||
EventTypeByteRange{"name", "name_length", "length"}, // the latter two are ideally the same
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -496,7 +504,7 @@ int main(int argc, char** argv) {
|
||||
{
|
||||
EventTypeTrivial{"uint32_t", "conference_number"},
|
||||
EventTypeTrivial{"uint32_t", "peer_number"},
|
||||
EventTypeByteRange{"title", "title_length", "length"}, // the later two are idealy the same
|
||||
EventTypeByteRange{"title", "title_length", "length"}, // the latter two are ideally the same
|
||||
}
|
||||
},
|
||||
|
||||
@ -516,7 +524,7 @@ int main(int argc, char** argv) {
|
||||
EventTypeTrivial{"uint32_t", "file_number"},
|
||||
EventTypeTrivial{"uint32_t", "kind"},
|
||||
EventTypeTrivial{"uint64_t", "file_size"},
|
||||
EventTypeByteRange{"filename", "filename_length", "length"}, // the later two are idealy the same
|
||||
EventTypeByteRange{"filename", "filename_length", "filename_length"},
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -525,7 +533,7 @@ int main(int argc, char** argv) {
|
||||
EventTypeTrivial{"uint32_t", "friend_number"},
|
||||
EventTypeTrivial{"uint32_t", "file_number"},
|
||||
EventTypeTrivial{"uint64_t", "position"},
|
||||
EventTypeByteRange{"data", "data_length", "length"}, // the later two are idealy the same
|
||||
EventTypeByteRange{"data", "data_length", "length"}, // the latter two are ideally the same
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -548,14 +556,14 @@ int main(int argc, char** argv) {
|
||||
"Friend_Lossless_Packet",
|
||||
{
|
||||
EventTypeTrivial{"uint32_t", "friend_number"},
|
||||
EventTypeByteRange{"data", "data_length", "length"}, // the later two are idealy the same
|
||||
EventTypeByteRange{"data", "data_length", "length"}, // the latter two are ideally the same
|
||||
}
|
||||
},
|
||||
{
|
||||
"Friend_Lossy_Packet",
|
||||
{
|
||||
EventTypeTrivial{"uint32_t", "friend_number"},
|
||||
EventTypeByteRange{"data", "data_length", "length"}, // the later two are idealy the same
|
||||
EventTypeByteRange{"data", "data_length", "length"}, // the latter two are ideally the same
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -563,14 +571,14 @@ int main(int argc, char** argv) {
|
||||
{
|
||||
EventTypeTrivial{"uint32_t", "friend_number"},
|
||||
EventTypeTrivial{"Tox_Message_Type", "type"},
|
||||
EventTypeByteRange{"message", "message_length", "length"}, // the later two are idealy the same
|
||||
EventTypeByteRange{"message", "message_length", "length"}, // the latter two are ideally the same
|
||||
}
|
||||
},
|
||||
{
|
||||
"Friend_Name",
|
||||
{
|
||||
EventTypeTrivial{"uint32_t", "friend_number"},
|
||||
EventTypeByteRange{"name", "name_length", "length"}, // the later two are idealy the same
|
||||
EventTypeByteRange{"name", "name_length", "length"}, // the latter two are ideally the same
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -585,7 +593,7 @@ int main(int argc, char** argv) {
|
||||
"Friend_Request",
|
||||
{
|
||||
//EventTypeTrivial{"uint32_t", "friend_number"}, // public_key ByteArray
|
||||
EventTypeByteRange{"message", "message_length", "length"}, // the later two are idealy the same
|
||||
EventTypeByteRange{"message", "message_length", "length"}, // the latter two are ideally the same
|
||||
}
|
||||
},
|
||||
#endif
|
||||
@ -600,7 +608,7 @@ int main(int argc, char** argv) {
|
||||
"Friend_Status_Message",
|
||||
{
|
||||
EventTypeTrivial{"uint32_t", "friend_number"},
|
||||
EventTypeByteRange{"message", "message_length", "length"}, // the later two are idealy the same
|
||||
EventTypeByteRange{"message", "message_length", "length"}, // the latter two are ideally the same
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -623,7 +631,7 @@ int main(int argc, char** argv) {
|
||||
{
|
||||
EventTypeTrivial{"uint32_t", "group_number"},
|
||||
EventTypeTrivial{"uint32_t", "peer_id"},
|
||||
EventTypeByteRange{"name", "name_length", "length"}, // the later two are idealy the same
|
||||
EventTypeByteRange{"name", "name_length", "length"}, // the latter two are ideally the same
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -639,7 +647,7 @@ int main(int argc, char** argv) {
|
||||
{
|
||||
EventTypeTrivial{"uint32_t", "group_number"},
|
||||
EventTypeTrivial{"uint32_t", "peer_id"},
|
||||
EventTypeByteRange{"topic", "topic_length", "length"}, // the later two are idealy the same
|
||||
EventTypeByteRange{"topic", "topic_length", "length"}, // the latter two are ideally the same
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -674,7 +682,7 @@ int main(int argc, char** argv) {
|
||||
"Group_Password",
|
||||
{
|
||||
EventTypeTrivial{"uint32_t", "group_number"},
|
||||
EventTypeByteRange{"password", "password_length", "length"}, // the later two are idealy the same
|
||||
EventTypeByteRange{"password", "password_length", "length"}, // the latter two are ideally the same
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -683,7 +691,7 @@ int main(int argc, char** argv) {
|
||||
EventTypeTrivial{"uint32_t", "group_number"},
|
||||
EventTypeTrivial{"uint32_t", "peer_id"},
|
||||
EventTypeTrivial{"Tox_Message_Type", "type"},
|
||||
EventTypeByteRange{"message", "message_length", "length"}, // the later two are idealy the same
|
||||
EventTypeByteRange{"message", "message_length", "length"}, // the latter two are ideally the same
|
||||
EventTypeTrivial{"uint32_t", "message_id"},
|
||||
}
|
||||
},
|
||||
@ -693,7 +701,7 @@ int main(int argc, char** argv) {
|
||||
EventTypeTrivial{"uint32_t", "group_number"},
|
||||
EventTypeTrivial{"uint32_t", "peer_id"},
|
||||
EventTypeTrivial{"Tox_Message_Type", "type"},
|
||||
EventTypeByteRange{"message", "message_length", "length"}, // the later two are idealy the same
|
||||
EventTypeByteRange{"message", "message_length", "length"}, // the latter two are ideally the same
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -701,7 +709,7 @@ int main(int argc, char** argv) {
|
||||
{
|
||||
EventTypeTrivial{"uint32_t", "group_number"},
|
||||
EventTypeTrivial{"uint32_t", "peer_id"},
|
||||
EventTypeByteRange{"data", "data_length", "length"}, // the later two are idealy the same
|
||||
EventTypeByteRange{"data", "data_length", "length"}, // the latter two are ideally the same
|
||||
}
|
||||
},
|
||||
{
|
||||
@ -709,14 +717,14 @@ int main(int argc, char** argv) {
|
||||
{
|
||||
EventTypeTrivial{"uint32_t", "group_number"},
|
||||
EventTypeTrivial{"uint32_t", "peer_id"},
|
||||
EventTypeByteRange{"data", "data_length", "length"}, // the later two are idealy the same
|
||||
EventTypeByteRange{"data", "data_length", "length"}, // the latter two are ideally the same
|
||||
}
|
||||
},
|
||||
{
|
||||
"Group_Invite",
|
||||
{
|
||||
EventTypeTrivial{"uint32_t", "friend_number"},
|
||||
EventTypeByteRange{"invite_data", "invite_data_length", "length"}, // the later two are idealy the same
|
||||
EventTypeByteRange{"invite_data", "invite_data_length", "length"}, // the latter two are ideally the same
|
||||
EventTypeByteRange{"group_name", "group_name_length", "group_name_length"}, // they are :)
|
||||
}
|
||||
},
|
||||
|
8
other/event_tooling/run
Executable file
8
other/event_tooling/run
Executable file
@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eux
|
||||
BUILD=events
|
||||
docker build -t "toxchat/c-toxcore:$BUILD" "other/event_tooling"
|
||||
docker run --rm -v "$PWD/toxcore/events:/src/out" -t "toxchat/c-toxcore:$BUILD"
|
||||
sed -i -e 's/, uint16_t length,/, size_t length,/' toxcore/events/file_chunk_request.c
|
||||
sed -i -e 's/^ 0/ TOX_CONNECTION_NONE/' toxcore/events/self_connection_status.c
|
@ -1,30 +1,41 @@
|
||||
function(target_link_toxcore target)
|
||||
if(TARGET toxcore_static)
|
||||
target_link_libraries(${target} PRIVATE toxcore_static)
|
||||
else()
|
||||
target_link_libraries(${target} PRIVATE toxcore_shared)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
add_executable(save-generator save-generator.c)
|
||||
target_link_modules(save-generator toxcore misc_tools)
|
||||
target_link_libraries(save-generator PRIVATE misc_tools)
|
||||
target_link_toxcore(save-generator)
|
||||
|
||||
add_executable(strkey strkey.c)
|
||||
target_link_modules(strkey toxcore ${LIBSODIUM_LIBRARIES})
|
||||
target_link_libraries(strkey PRIVATE ${LIBSODIUM_LIBRARIES})
|
||||
target_link_toxcore(strkey)
|
||||
|
||||
add_executable(create_bootstrap_keys create_bootstrap_keys.c)
|
||||
target_link_modules(create_bootstrap_keys ${LIBSODIUM_LIBRARIES})
|
||||
target_link_libraries(create_bootstrap_keys PRIVATE ${LIBSODIUM_LIBRARIES})
|
||||
target_link_toxcore(create_bootstrap_keys)
|
||||
|
||||
add_executable(create_minimal_savedata create_minimal_savedata.c)
|
||||
target_link_modules(create_minimal_savedata ${LIBSODIUM_LIBRARIES})
|
||||
target_link_libraries(create_minimal_savedata PRIVATE ${LIBSODIUM_LIBRARIES})
|
||||
|
||||
add_executable(create_savedata create_savedata.c)
|
||||
target_link_modules(create_savedata toxcore ${LIBSODIUM_LIBRARIES})
|
||||
target_link_libraries(create_savedata PRIVATE ${LIBSODIUM_LIBRARIES})
|
||||
target_link_toxcore(create_savedata)
|
||||
|
||||
add_executable(sign sign.c)
|
||||
target_link_modules(sign ${LIBSODIUM_LIBRARIES} misc_tools)
|
||||
target_link_libraries(sign PRIVATE ${LIBSODIUM_LIBRARIES} misc_tools)
|
||||
|
||||
add_executable(cracker_simple cracker_simple.c)
|
||||
target_link_modules(cracker_simple ${LIBSODIUM_LIBRARIES} misc_tools)
|
||||
target_link_libraries(cracker_simple ${LIBSODIUM_LIBRARIES} misc_tools)
|
||||
|
||||
# MSVC doesn't support OpenMP
|
||||
if(NOT MSVC)
|
||||
find_package(OpenMP)
|
||||
if(OpenMP_C_FOUND)
|
||||
add_executable(cracker cracker.c)
|
||||
target_link_modules(cracker ${LIBSODIUM_LIBRARIES})
|
||||
target_link_libraries(cracker OpenMP::OpenMP_C)
|
||||
target_link_libraries(cracker PRIVATE OpenMP::OpenMP_C ${LIBSODIUM_LIBRARIES})
|
||||
endif()
|
||||
endif()
|
||||
|
@ -41,7 +41,7 @@ static bool create_tox(const unsigned char *const secret_key, Tox **const tox)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool print_savedata(Tox *const tox)
|
||||
static bool print_savedata(const Tox *const tox)
|
||||
{
|
||||
const size_t savedata_size = tox_get_savedata_size(tox);
|
||||
uint8_t *const savedata = (uint8_t *)malloc(savedata_size);
|
||||
|
@ -61,7 +61,7 @@ static void tox_connection_callback(Tox *tox, Tox_Connection connection, void *u
|
||||
}
|
||||
}
|
||||
|
||||
static void print_information(Tox *tox)
|
||||
static void print_information(const Tox *tox)
|
||||
{
|
||||
uint8_t tox_id[TOX_ADDRESS_SIZE];
|
||||
char tox_id_str[TOX_ADDRESS_SIZE * 2];
|
||||
|
@ -21,7 +21,7 @@
|
||||
#include "../../testing/misc_tools.h" // hex_string_to_bin
|
||||
#include "../../toxcore/ccompat.h"
|
||||
|
||||
static int load_file(char *filename, unsigned char **result)
|
||||
static int load_file(const char *filename, unsigned char **result)
|
||||
{
|
||||
int size = 0;
|
||||
FILE *f = fopen(filename, "rb");
|
||||
|
@ -2,7 +2,7 @@
|
||||
*
|
||||
* Generates Tox's key pairs, checking if a certain string is in the public key.
|
||||
*
|
||||
* Requires sodium or nacl library.
|
||||
* Requires sodium library.
|
||||
*
|
||||
* There seem to be some problems with the code working on Windows -- it works
|
||||
* when built in debug mode with MinGW 4.8, but it doesn't work correctly when
|
||||
@ -45,7 +45,7 @@
|
||||
|
||||
#define PRINT_TRIES_COUNT
|
||||
|
||||
static void print_key(unsigned char *key)
|
||||
static void print_key(const unsigned char *key)
|
||||
{
|
||||
for (size_t i = 0; i < crypto_box_PUBLICKEYBYTES; ++i) {
|
||||
if (key[i] < 16) {
|
||||
@ -125,7 +125,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
} while (!found);
|
||||
} else {
|
||||
unsigned char *p = public_key + offset;
|
||||
const unsigned char *p = public_key + offset;
|
||||
|
||||
do {
|
||||
#ifdef PRINT_TRIES_COUNT
|
||||
|
@ -6,8 +6,11 @@
|
||||
#
|
||||
# Example:
|
||||
#
|
||||
# other/make_single_file testing/misc_tools.c auto_tests/send_message_test.c | \
|
||||
# tcc -o send_message_test - $(pkg-config --cflags --libs libsodium opus vpx)
|
||||
# other/make_single_file auto_tests/toxav_basic_test.c auto_tests/auto_test_support.c testing/misc_tools.c | \
|
||||
# tcc -o toxav_basic_test - $(pkg-config --cflags --libs libsodium opus vpx)
|
||||
#
|
||||
# other/make_single_file -core auto_tests/send_message_test.c auto_tests/auto_test_support.c testing/misc_tools.c | \
|
||||
# tcc -o send_message_test - $(pkg-config --cflags --libs libsodium)
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
@ -44,7 +47,7 @@ sub emit {
|
||||
|
||||
if (@ARGV and $ARGV[0] eq "-core") {
|
||||
shift @ARGV;
|
||||
for my $fn (<toxcore/*.c>, <third_party/cmp/*.c>) {
|
||||
for my $fn (<toxcore/*.c>, <toxcore/*/*.c>, <third_party/cmp/*.c>) {
|
||||
emit(abs_path $fn);
|
||||
}
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user