diff --git a/CMakeLists.txt b/CMakeLists.txt index e80e401..53972ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ add_subdirectory(libtgvoip) find_package(PkgConfig REQUIRED) find_package(Threads REQUIRED) -find_package(Td 1.2.0 REQUIRED) +find_package(Td 1.6.0 REQUIRED) find_package(spdlog 0.17 REQUIRED) pkg_check_modules(PJSIP libpjproject>=2.8 REQUIRED) pkg_check_modules(OPUS opus REQUIRED) diff --git a/buildenv/Dockerfile.bionic b/buildenv/Dockerfile.bionic index b35d38a..480e682 100644 --- a/buildenv/Dockerfile.bionic +++ b/buildenv/Dockerfile.bionic @@ -8,21 +8,21 @@ RUN apt-get update \ zlib1g-dev gperf ccache \ && rm -rf /var/lib/apt/lists/* -RUN wget https://cmake.org/files/v3.9/cmake-3.9.6-Linux-x86_64.sh \ - && sh cmake-3.9.6-Linux-x86_64.sh --prefix=/usr --exclude-subdir +RUN wget https://cmake.org/files/v3.18/cmake-3.18.0-Linux-x86_64.sh \ + && sh cmake-3.18.0-Linux-x86_64.sh --prefix=/usr --exclude-subdir COPY tdlib_header.patch / COPY tdlib_threadname.patch / RUN git clone https://github.com/tdlib/td.git \ && cd td \ - && git reset --hard v1.2.0 \ + && git reset --hard v1.6.0 \ && git apply /tdlib_header.patch \ && git apply /tdlib_threadname.patch \ && mkdir build \ && cd build \ && cmake -DCMAKE_BUILD_TYPE=Release .. \ - && cmake --build . --target install \ + && cmake --build . --target install -j $(grep -c ^processor /proc/cpuinfo) \ && cd / \ && rm -rf td @@ -33,7 +33,7 @@ RUN git clone https://github.com/pjsip/pjproject.git \ && git reset --hard 2.9 \ && cp /config_site.h pjlib/include/pj \ && ./configure --disable-sound CFLAGS="-O3 -DNDEBUG" \ - && make dep && make && make install \ + && make dep && make -j $(grep -c ^processor /proc/cpuinfo) && make install \ && cd / \ && rm -rf pjproject @@ -43,6 +43,6 @@ RUN git clone -n https://github.com/gabime/spdlog.git \ && mkdir build \ && cd build \ && cmake -DCMAKE_BUILD_TYPE=Release -DSPDLOG_BUILD_EXAMPLES=OFF -DSPDLOG_BUILD_TESTING=OFF .. \ - && cmake --build . --target install \ + && cmake --build . --target install -j $(grep -c ^processor /proc/cpuinfo) \ && cd / \ && rm -rf spdlog \ No newline at end of file diff --git a/buildenv/Dockerfile.centos6 b/buildenv/Dockerfile.centos6 index 6b4b04f..d6f951d 100644 --- a/buildenv/Dockerfile.centos6 +++ b/buildenv/Dockerfile.centos6 @@ -7,7 +7,7 @@ RUN yum -y install centos-release-scl yum-utils \ RUN set -xe \ && yum install -y \ - make \ + make patch \ git wget \ zlib-devel openssl-devel gperf \ pkgconfig ccache gperf unzip \ @@ -15,8 +15,27 @@ RUN set -xe \ epel-release \ && yum install -y opus-devel patchelf -RUN wget https://cmake.org/files/v3.9/cmake-3.9.6-Linux-x86_64.sh \ - && sh cmake-3.9.6-Linux-x86_64.sh --prefix=/usr --exclude-subdir +RUN wget https://cmake.org/files/v3.18/cmake-3.18.0-Linux-x86_64.sh \ + && sh cmake-3.18.0-Linux-x86_64.sh --prefix=/usr --exclude-subdir + +COPY glibc_gcc.patch / + +RUN source /opt/rh/devtoolset-7/enable \ + && wget http://ftp.gnu.org/gnu/glibc/glibc-2.14.tar.gz \ + && tar zxf glibc-2.14.tar.gz \ + && rm glibc-2.14.tar.gz \ + && cd glibc-2.14 \ + && patch < /glibc_gcc.patch \ + && gcc --version \ + && mkdir build \ + && cd build \ + && ../configure --prefix=/opt/glibc-2.14 \ + && make -j $(grep -c ^processor /proc/cpuinfo) \ + && make install \ + && cd / \ + && rm -rf glibc-2.14 \ + +ENV LD_LIBRARY_PATH="/opt/glibc-2.14/lib:${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" COPY tdlib_header.patch / COPY tdlib_threadname.patch / @@ -24,13 +43,14 @@ COPY tdlib_threadname.patch / RUN source /opt/rh/devtoolset-7/enable \ && git clone https://github.com/tdlib/td.git \ && cd td \ - && git reset --hard v1.2.0 \ + && git reset --hard v1.6.0 \ && git apply /tdlib_header.patch \ && git apply /tdlib_threadname.patch \ && mkdir build \ && cd build \ + && export CPLUS_INCLUDE_PATH="/opt/glibc-2.14/include" \ && cmake -DCMAKE_BUILD_TYPE=Release .. \ - && cmake --build . --target install \ + && cmake --build . --target install -j $(grep -c ^processor /proc/cpuinfo) \ && cd / \ && rm -rf td @@ -42,7 +62,7 @@ RUN source /opt/rh/devtoolset-7/enable \ && git reset --hard 2.9 \ && cp /config_site.h pjlib/include/pj \ && ./configure --disable-sound CFLAGS="-O3 -DNDEBUG" \ - && make dep && make && make install \ + && make dep && make -j $(grep -c ^processor /proc/cpuinfo) && make install \ && cd / \ && rm -rf pjproject @@ -53,7 +73,7 @@ RUN source /opt/rh/devtoolset-7/enable \ && mkdir build \ && cd build \ && cmake -DCMAKE_BUILD_TYPE=Release -DSPDLOG_BUILD_EXAMPLES=OFF -DSPDLOG_BUILD_TESTING=OFF .. \ - && cmake --build . --target install \ + && cmake --build . --target install -j $(grep -c ^processor /proc/cpuinfo) \ && cd / \ && rm -rf spdlog @@ -64,7 +84,7 @@ RUN source /opt/rh/devtoolset-7/enable \ && mkdir build \ && cd build \ && export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig && cmake -DCMAKE_BUILD_TYPE=Release -DUSE_SYSTEM_CIMG=0 .. \ - && cmake --build . \ + && cmake --build . -j $(grep -c ^processor /proc/cpuinfo) \ && cp bin/linuxdeploy /usr/local/bin \ && cd / \ && rm -rf linuxdeploy diff --git a/buildenv/Dockerfile.centos7 b/buildenv/Dockerfile.centos7 index b1c1b3a..cb78527 100644 --- a/buildenv/Dockerfile.centos7 +++ b/buildenv/Dockerfile.centos7 @@ -11,8 +11,8 @@ RUN yum install -y \ zlib-devel opus-devel openssl-devel gperf \ pkgconfig ccache gperf unzip -RUN wget https://cmake.org/files/v3.9/cmake-3.9.6-Linux-x86_64.sh \ - && sh cmake-3.9.6-Linux-x86_64.sh --prefix=/usr --exclude-subdir +RUN wget https://cmake.org/files/v3.18/cmake-3.18.0-Linux-x86_64.sh \ + && sh cmake-3.18.0-Linux-x86_64.sh --prefix=/usr --exclude-subdir COPY tdlib_header.patch / COPY tdlib_threadname.patch / @@ -20,13 +20,13 @@ COPY tdlib_threadname.patch / RUN source /opt/rh/devtoolset-7/enable \ && git clone https://github.com/tdlib/td.git \ && cd td \ - && git reset --hard v1.2.0 \ + && git reset --hard v1.6.0 \ && git apply /tdlib_header.patch \ && git apply /tdlib_threadname.patch \ && mkdir build \ && cd build \ && cmake -DCMAKE_BUILD_TYPE=Release .. \ - && cmake --build . --target install \ + && cmake --build . --target install -j $(grep -c ^processor /proc/cpuinfo) \ && cd / \ && rm -rf td @@ -38,7 +38,7 @@ RUN source /opt/rh/devtoolset-7/enable \ && git reset --hard 2.9 \ && cp /config_site.h pjlib/include/pj \ && ./configure --disable-sound CFLAGS="-O3 -DNDEBUG" \ - && make dep && make && make install \ + && make dep && make -j $(grep -c ^processor /proc/cpuinfo) && make install \ && cd / \ && rm -rf pjproject @@ -49,7 +49,7 @@ RUN source /opt/rh/devtoolset-7/enable \ && mkdir build \ && cd build \ && cmake -DCMAKE_BUILD_TYPE=Release -DSPDLOG_BUILD_EXAMPLES=OFF -DSPDLOG_BUILD_TESTING=OFF .. \ - && cmake --build . --target install \ + && cmake --build . --target install -j $(grep -c ^processor /proc/cpuinfo) \ && cd / \ && rm -rf spdlog diff --git a/buildenv/glibc_gcc.patch b/buildenv/glibc_gcc.patch new file mode 100644 index 0000000..dfd18fb --- /dev/null +++ b/buildenv/glibc_gcc.patch @@ -0,0 +1,17 @@ +diff --git a/configure b/configure +index 6cf85e5..2613fc4 100755 +--- a/configure ++++ b/configure +@@ -4938,10 +4938,10 @@ else + $as_echo_n "checking version of $CC... " >&6; } + ac_prog_version=`$CC -v 2>&1 | sed -n 's/^.*version \([egcygnustpi-]*[0-9.]*\).*$/\1/p'` + case $ac_prog_version in +- '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;; ++ '') ac_prog_version="v. ?.??, bad"; ac_verc_fail=no;; + 3.4* | 4.[0-9]* ) + ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;; +- *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;; ++ *) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=no;; + + esac + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_prog_version" >&5 diff --git a/buildenv/prepare.sh b/buildenv/prepare.sh index 5590b1b..de1347d 100755 --- a/buildenv/prepare.sh +++ b/buildenv/prepare.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + DOCKER_IMAGE=infactum/tg2sip-builder for DOCKER_TAG in bionic centos6 centos7 diff --git a/buildenv/tdlib_header.patch b/buildenv/tdlib_header.patch index c79ea26..0f74916 100644 --- a/buildenv/tdlib_header.patch +++ b/buildenv/tdlib_header.patch @@ -1,19 +1,19 @@ diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp -index a150e6c..cd66d91 100644 +index eafec324..3cce46f5 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp -@@ -4827,10 +4827,10 @@ Status Td::set_parameters(td_api::object_ptr parameters - if (options.application_version.empty()) { +@@ -4899,10 +4899,10 @@ Status Td::set_parameters(td_api::object_ptr parameters + if (options_.application_version.empty()) { return Status::Error(400, "Application version must be non-empty"); } -- if (options.api_id != 21724) { -- options.application_version += ", TDLib "; -- options.application_version += TDLIB_VERSION; +- if (options_.api_id != 21724) { +- options_.application_version += ", TDLib "; +- options_.application_version += TDLIB_VERSION; - } -+ // if (options.api_id != 21724) { -+ // options.application_version += ", TDLib "; -+ // options.application_version += TDLIB_VERSION; ++ // if (options_.api_id != 21724) { ++ // options_.application_version += ", TDLib "; ++ // options_.application_version += TDLIB_VERSION; + // } - G()->set_mtproto_header(std::make_unique(options)); - - state_ = State::Decrypt; + options_.language_pack = ""; + options_.language_code = ""; + options_.parameters = ""; diff --git a/buildenv/tdlib_threadname.patch b/buildenv/tdlib_threadname.patch index 802dfb5..a1c8380 100644 --- a/buildenv/tdlib_threadname.patch +++ b/buildenv/tdlib_threadname.patch @@ -1,8 +1,8 @@ diff --git a/tdutils/td/utils/port/detail/ThreadStl.h b/tdutils/td/utils/port/detail/ThreadStl.h -index 64bf321..68d3bf6 100644 +index ef6ff475..c0e18ee4 100644 --- a/tdutils/td/utils/port/detail/ThreadStl.h +++ b/tdutils/td/utils/port/detail/ThreadStl.h -@@ -37,6 +37,7 @@ class ThreadStl { +@@ -41,6 +41,7 @@ class ThreadStl { invoke_tuple(std::move(args)); clear_thread_locals(); }); diff --git a/tg2sip/gateway.cpp b/tg2sip/gateway.cpp index e242437..bf32e03 100755 --- a/tg2sip/gateway.cpp +++ b/tg2sip/gateway.cpp @@ -57,12 +57,9 @@ namespace state_machine::guards { // the event type 16 (flash) as stated in RFC 4730. // PJSUA maximum number of characters are 32. - auto content = td_api::move_object_as(event->message_->content_); + auto text = static_cast(*event->message_->content_).text_->text_; const std::regex dtmf_regex("^[0-9A-D*#]{1,32}$"); - auto result = regex_match(content->text_->text_, dtmf_regex); - - // Don't forget to put data back! - event->message_->content_ = td_api::move_object_as(content); + auto result = regex_match(text, dtmf_regex); return result; } @@ -312,7 +309,7 @@ namespace state_machine::actions { using namespace tgvoip; - auto state = td_api::move_object_as(event->call_->state_); + const auto &state = static_cast(*event->call_->state_); auto voip_controller = std::make_shared(); static auto config = VoIPController::Config( @@ -336,11 +333,11 @@ namespace state_machine::actions { } char encryption_key[256]; - memcpy(encryption_key, state->encryption_key_.c_str(), 256); + memcpy(encryption_key, state.encryption_key_.c_str(), 256); voip_controller->SetEncryptionKey(encryption_key, event->call_->is_outgoing_); vector endpoints; - for (auto &connection : state->connections_) { + for (const auto &connection : state.connections_) { unsigned char peer_tag[16]; memcpy(peer_tag, connection->peer_tag_.c_str(), 16); auto ipv4 = IPv4Address(connection->ip_); @@ -566,10 +563,10 @@ namespace state_machine::actions { const td_api::object_ptr &event, std::shared_ptr logger) const { - auto content = td_api::move_object_as(event->message_->content_); - DEBUG(logger, "[{}] sending DTMF {}", ctx.id(), content->text_->text_); + auto text = static_cast(*event->message_->content_).text_->text_; + DEBUG(logger, "[{}] sending DTMF {}", ctx.id(), text); try { - sip_client.DialDtmf(ctx.sip_call_id, content->text_->text_); + sip_client.DialDtmf(ctx.sip_call_id, text); } catch (const pj::Error &error) { logger->error(error.reason); } diff --git a/tg2sip/gen_db.cpp b/tg2sip/gen_db.cpp index 35bf917..91e0201 100644 --- a/tg2sip/gen_db.cpp +++ b/tg2sip/gen_db.cpp @@ -152,21 +152,22 @@ private: sequence_done = true; std::cerr << "Terminated" << std::endl; }, - [this](td_api::authorizationStateWaitCode &wait_code) { - std::string first_name; - std::string last_name; - if (!wait_code.is_registered_) { - std::cerr << "Enter your first name: "; - std::cin >> first_name; - std::cerr << "Enter your last name: "; - std::cin >> last_name; - } - std::cerr << "Enter authentication code: "; + [this](td_api::authorizationStateWaitCode &) { + std::cout << "Enter authentication code: " << std::flush; std::string code; std::cin >> code; - send_query( - td_api::make_object(code, first_name, last_name), - create_authentication_query_handler()); + send_query(td_api::make_object(code), + create_authentication_query_handler()); + }, + [this](td_api::authorizationStateWaitRegistration &) { + std::string first_name; + std::string last_name; + std::cout << "Enter your first name: " << std::flush; + std::cin >> first_name; + std::cout << "Enter your last name: " << std::flush; + std::cin >> last_name; + send_query(td_api::make_object(first_name, last_name), + create_authentication_query_handler()); }, [this](td_api::authorizationStateWaitPassword &) { std::cerr << "Enter authentication password: "; @@ -175,34 +176,35 @@ private: send_query(td_api::make_object(password), create_authentication_query_handler()); }, + [this](td_api::authorizationStateWaitOtherDeviceConfirmation &state) { + std::cout << "Confirm this login link on another device: " << state.link_ << std::endl; + }, [this](td_api::authorizationStateWaitPhoneNumber &) { - std::cerr << "Enter phone number: "; + std::cout << "Enter phone number: " << std::flush; std::string phone_number; std::cin >> phone_number; - send_query(td_api::make_object( - phone_number, false /*allow_flash_calls*/, false /*is_current_phone_number*/), + send_query(td_api::make_object(phone_number, nullptr), create_authentication_query_handler()); }, [this](td_api::authorizationStateWaitEncryptionKey &) { send_query(td_api::make_object(""), create_authentication_query_handler()); - td_api::object_ptr proxy; if (settings.proxy_enabled()) { - auto socks_proxy = td_api::make_object( - settings.proxy_address(), - settings.proxy_port(), + auto socks_proxy_type = td_api::make_object( settings.proxy_username(), settings.proxy_password() ); - proxy = td_api::move_object_as(socks_proxy); + send_query(td_api::make_object( + settings.proxy_address(), + settings.proxy_port(), + true, + td_api::move_object_as(socks_proxy_type)), + [](Object) {}); } else { - auto empty_proxy = td_api::make_object(); - proxy = td_api::move_object_as(empty_proxy); + send_query(td_api::make_object(), [](Object) {}); } - send_query(td_api::make_object( - td_api::move_object_as(proxy)), - [](Object) {}); + }, [this](td_api::authorizationStateWaitTdlibParameters &) { auto lib_parameters = td_api::make_object(); diff --git a/tg2sip/tg.cpp b/tg2sip/tg.cpp index 806c12e..8641c1f 100755 --- a/tg2sip/tg.cpp +++ b/tg2sip/tg.cpp @@ -21,7 +21,7 @@ using namespace tg; Client::Client(Settings &settings, std::shared_ptr logger_, - OptionalQueue &events_) + OptionalQueue &events_) : logger(std::move(logger_)), events(events_) { client = std::make_unique(); @@ -60,16 +60,17 @@ void Client::init_lib_parameters(Settings &settings) { void Client::init_proxy(Settings &settings) { if (settings.proxy_enabled()) { - auto socks_proxy = td_api::make_object( - settings.proxy_address(), - settings.proxy_port(), + auto socks_proxy_type = td_api::make_object( settings.proxy_username(), settings.proxy_password() ); - proxy = td_api::move_object_as(socks_proxy); + set_proxy = td_api::make_object( + settings.proxy_address(), + settings.proxy_port(), + true, + td_api::move_object_as(socks_proxy_type)); } else { - auto empty_proxy = td_api::make_object(); - proxy = td_api::move_object_as(empty_proxy); + set_proxy = td_api::make_object(); } } @@ -186,8 +187,7 @@ void Client::on_authorization_state_update(td_api::object_ptr(), create_authentication_query_handler()); - send_query(td_api::make_object(td_api::move_object_as(proxy)), - create_authentication_query_handler()); + send_query(std::move(set_proxy), create_authentication_query_handler()); break; case td_api::authorizationStateWaitTdlibParameters::ID: { send_query(td_api::make_object( diff --git a/tg2sip/tg.h b/tg2sip/tg.h index 484d86b..a01d35d 100755 --- a/tg2sip/tg.h +++ b/tg2sip/tg.h @@ -57,8 +57,8 @@ namespace tg { const double WAIT_TIMEOUT = 10; std::unique_ptr client; - std::unique_ptr lib_parameters; - td_api::object_ptr proxy; + td::tl::unique_ptr lib_parameters; + td_api::object_ptr set_proxy; std::thread thread_;