diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d8b1436..9350b26 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -179,3 +179,58 @@ jobs: allowUpdates: true token: ${{ secrets.GH_TOKEN }} + tinyphone_linux_job: + name: Build Tinyphone Linux + runs-on: ubuntu-20.04 + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: '1' + submodules: 'recursive' + + - name: Install Dependencies + shell: bash + run : | + sudo apt-get install -y build-essential cmake libcurl4-openssl-dev pkg-config libboost1.71-all-dev libasound-dev + + - name: Compile Libraries + run : | + pushd lib/cryptopp/ + make + sudo make install + popd + + pushd lib/json + mkdir build + cd build + cmake .. + make + sudo make install + popd + + pushd lib/portaudio + git checkout master #some issue with rb-hotplug-wmme branch + ./configure + make + sudo make install + popd + + pushd lib/pjproject + ./configure + make realclean + make dep + make + sudo make install + popd + + + - name: Build Project + run : | + pushd tinyphone-linux + mkdir build + cd build + cmake -DCMAKE_BUILD_TYPE=Release .. + make + + diff --git a/Vagrantfile b/Vagrantfile new file mode 100644 index 0000000..eca29fa --- /dev/null +++ b/Vagrantfile @@ -0,0 +1,71 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +# All Vagrant configuration is done below. The "2" in Vagrant.configure +# configures the configuration version (we support older styles for +# backwards compatibility). Please don't change it unless you know what +# you're doing. +Vagrant.configure("2") do |config| + # The most common configuration options are documented and commented below. + # For a complete reference, please see the online documentation at + # https://docs.vagrantup.com. + + # Every Vagrant development environment requires a box. You can search for + # boxes at https://vagrantcloud.com/search. + config.vm.box = "bento/ubuntu-20.04" + + # Disable automatic box update checking. If you disable this, then + # boxes will only be checked for updates when the user runs + # `vagrant box outdated`. This is not recommended. + config.vm.box_check_update = false + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine. In the example below, + # accessing "localhost:8080" will access port 80 on the guest machine. + # NOTE: This will enable public access to the opened port + # config.vm.network "forwarded_port", guest: 80, host: 8080 + + # Create a forwarded port mapping which allows access to a specific port + # within the machine from a port on the host machine and only allow access + # via 127.0.0.1 to disable public access + # config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1" + + # Create a private network, which allows host-only access to the machine + # using a specific IP. + # config.vm.network "private_network", ip: "192.168.33.10" + + # Create a public network, which generally matched to bridged network. + # Bridged networks make the machine appear as another physical device on + # your network. + # config.vm.network "public_network" + + # Share an additional folder to the guest VM. The first argument is + # the path on the host to the actual folder. The second argument is + # the path on the guest to mount the folder. And the optional third + # argument is a set of non-required options. + config.vm.synced_folder ".", "/vagrant" + + # Provider-specific configuration so you can fine-tune various + # backing providers for Vagrant. These expose provider-specific options. + # Example for VirtualBox: + # + config.vm.provider "virtualbox" do |vb| + # # Display the VirtualBox GUI when booting the machine + # vb.gui = true + # + # # Customize the amount of memory on the VM: + vb.memory = "2048" + end + # + # View the documentation for the provider you are using for more + # information on available options. + + # Enable provisioning with a shell script. Additional provisioners such as + # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the + # documentation for more information about their specific syntax and use. + config.vm.provision "shell", inline: <<-SHELL + apt-get update + apt-get install -y build-essential cmake libcurl4-openssl-dev pkg-config libboost1.71-all-dev qtbase5-dev + + SHELL +end diff --git a/tinyphone-linux/CMakeLists.txt b/tinyphone-linux/CMakeLists.txt new file mode 100644 index 0000000..d8fc548 --- /dev/null +++ b/tinyphone-linux/CMakeLists.txt @@ -0,0 +1,106 @@ +# CMakeLists.txt + +cmake_minimum_required(VERSION 3.11) + +project(tinyphone LANGUAGES C CXX) +set(PACKAGE "${PROJECT_NAME}") +set(PACKAGE_NAME "${PROJECT_NAME}") +set(PACKAGE_VERSION "1.0.0") +set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") +set(PACKAGE_BUGREPORT "hi@kinsh.uk") +set(PACKAGE_TARNAME "${PROJECT_NAME}") +set(PACKAGE_URL "") +set(VERSION "${PACKAGE_VERSION}") + +# CMake Policies + +# CMP0074: find_package() uses _ROOT variables. +if(POLICY CMP0074) + cmake_policy(SET CMP0074 NEW) +endif() + +# CMP0075 Include file check macros honor CMAKE_REQUIRED_LIBRARIES +if(POLICY CMP0075) + cmake_policy(SET CMP0075 NEW) +endif() + + +# set(CMAKE_C_COMPILER "/usr/bin/gcc") +# set(CMAKE_CXX_COMPILER "g++") +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_WARN_DEPRECATED FALSE) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated") +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG") + +if(CMAKE_VERSION VERSION_LESS "3.7.0") + set(CMAKE_INCLUDE_CURRENT_DIR ON) +endif() + +include(CheckLibraryExists) +include(CheckSymbolExists) +include(CheckCSourceCompiles) +# include(CMakePushCheckState) +# include(GNUInstallDirs) +# include(CMakeDependentOption) + + +set(Boost_USE_STATIC_LIBS ON) +set(Boost_USE_MULTITHREADED ON) +# set(Boost_USE_STATIC_RUNTIME OFF) +find_package(Boost 1.71 REQUIRED COMPONENTS date_time filesystem system) +include_directories(${Boost_INCLUDE_DIRS}) + +find_package(PkgConfig REQUIRED) +pkg_check_modules(PJSIP libpjproject REQUIRED) +include_directories(${PJSIP_INCLUDE_DIRS}) + +check_symbol_exists("res_ndestroy" "resolv.h" HAVE_RES_NDESTROY) +set(CMAKE_REQUIRED_LIBRARIES resolv) + +find_package(Threads) + + +file(GLOB SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/../tinyphone/*.h + ${CMAKE_CURRENT_SOURCE_DIR}/../tinyphone/*.cpp +) +list(REMOVE_ITEM SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../tinyphone/guicon.cpp) +list(REMOVE_ITEM SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../tinyphone/splash.cpp) +list(REMOVE_ITEM SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../tinyphone/guicon.h) +list(REMOVE_ITEM SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../tinyphone/splash.h) +list(REMOVE_ITEM SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../tinyphone/winapp.cpp) + +add_executable(tinyphone ${SOURCES} console.cpp) +target_include_directories(tinyphone PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/pjproject/pjlib/include) +target_include_directories(tinyphone PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/pjproject/pjlib-util/include) +target_include_directories(tinyphone PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/pjproject/pjmedia/include) +target_include_directories(tinyphone PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/pjproject/pjnath/include) +target_include_directories(tinyphone PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/pjproject/pjsip/include) +target_include_directories(tinyphone PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/json/include) +target_include_directories(tinyphone PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/statsd-cpp/include) +target_include_directories(tinyphone PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/crow/include) +target_include_directories(tinyphone PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib/portaudio/include) +target_include_directories(tinyphone PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../lib) +target_include_directories(tinyphone PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../tinyphone) +link_directories(tinyphone ${Boost_LIBRARY_DIRS}) +target_link_libraries(tinyphone ${Boost_LIBRARIES}) +target_link_libraries(tinyphone ${PJSIP_LIBRARIES}) + +find_package(nlohmann_json 3.10.5 REQUIRED) +target_link_libraries(tinyphone nlohmann_json::nlohmann_json) + +add_library(libcryptopp_static STATIC IMPORTED) +set_target_properties(libcryptopp_static PROPERTIES IMPORTED_LOCATION /usr/local/lib/libcryptopp.a) +set_target_properties(libcryptopp_static PROPERTIES INTERFACE_INCLUDE_DIRECTORIES /usr/local/include) +target_link_libraries(tinyphone libcryptopp_static) +target_link_libraries(tinyphone "cryptopp") + +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../lib/statsd-cpp ${CMAKE_CURRENT_SOURCE_DIR}/../lib/statsd-cpp/build) +target_link_libraries(tinyphone statsd_static) + +pkg_check_modules(CURL libcurl REQUIRED) +include_directories(${CURL_INCLUDE_DIR}) +target_link_libraries(tinyphone ${CURL_LIBRARIES}) + + diff --git a/tinyphone-linux/console.cpp b/tinyphone-linux/console.cpp new file mode 100644 index 0000000..4a48a3b --- /dev/null +++ b/tinyphone-linux/console.cpp @@ -0,0 +1,37 @@ +// console.cpp : Defines the entry point for the console application. + +#include +#include +#include +#include +#include + +#include "server.h" +#include "utils.h" +#include "net.h" +#include "consts.h" +#include "config.h" +#include "log.h" +#include "app.hpp" +#include "tpendpoint.h" + +using namespace std; +using namespace pj; +using namespace tp; + + +void Start(){ + tp::StartApp(); + exit(0); +} + +void Stop(){ + tp::StopApp(); +} + +int main(int argc, char *argv[]) +{ + std::cout << "Hello Tinyphone!\n"; + Start(); + return 0; +} diff --git a/tinyphone-osx/src/osxapp.cpp b/tinyphone-osx/src/osxapp.cpp index cbc163a..91037a6 100644 --- a/tinyphone-osx/src/osxapp.cpp +++ b/tinyphone-osx/src/osxapp.cpp @@ -9,12 +9,7 @@ #include #include #include -#include -#include -#include -#include #include - #include #include "server.h" @@ -31,32 +26,6 @@ using namespace std; using namespace pj; using namespace tp; -namespace tp { - - std::vector GetLocalDNSServers() { - std::vector dnsServers; - // Get native iOS System Resolvers - res_ninit(&_res); - res_state res = &_res; - - for (int i = 0; i < res->nscount; i++) { - sa_family_t family = res->nsaddr_list[i].sin_family; - int port = ntohs(res->nsaddr_list[i].sin_port); - if (family == AF_INET) { // IPV4 address - char str[INET_ADDRSTRLEN]; // String representation of address - inet_ntop(AF_INET, & (res->nsaddr_list[i].sin_addr.s_addr), str, INET_ADDRSTRLEN); - dnsServers.push_back(str); - - } else if (family == AF_INET6) { // IPV6 address - char str[INET6_ADDRSTRLEN]; // String representation of address - inet_ntop(AF_INET6, &(res->nsaddr_list [i].sin_addr.s_addr), str, INET6_ADDRSTRLEN); - } - } - res_ndestroy(res); - return dnsServers; - } -} - void Start(){ tp::StartApp(); exit(0); diff --git a/tinyphone/baseapp.cpp b/tinyphone/baseapp.cpp index cf076d1..71a60ca 100644 --- a/tinyphone/baseapp.cpp +++ b/tinyphone/baseapp.cpp @@ -12,6 +12,12 @@ #include #include +#ifndef _WIN32 +#include +#include +#include +#endif + using namespace std; using namespace pj; @@ -30,6 +36,37 @@ namespace tp { TinyPhoneHttpServer* tpHttpServer; tp::Endpoint ep; +#ifndef _WIN32 + + std::vector GetLocalDNSServers() { + std::vector dnsServers; + // Get native iOS System Resolvers + res_ninit(&_res); + res_state res = &_res; + + for (int i = 0; i < res->nscount; i++) { + sa_family_t family = res->nsaddr_list[i].sin_family; + int port = ntohs(res->nsaddr_list[i].sin_port); + if (family == AF_INET) { // IPV4 address + char str[INET_ADDRSTRLEN]; // String representation of address + inet_ntop(AF_INET, & (res->nsaddr_list[i].sin_addr.s_addr), str, INET_ADDRSTRLEN); + dnsServers.push_back(str); + + } else if (family == AF_INET6) { // IPV6 address + char str[INET6_ADDRSTRLEN]; // String representation of address + inet_ntop(AF_INET6, &(res->nsaddr_list [i].sin_addr.s_addr), str, INET6_ADDRSTRLEN); + } + } +#ifndef HAVE_RES_NDESTROY + res_nclose(res); +#else + res_ndestroy(res); +#endif + return dnsServers; + } + +#endif + void InitPJSUAEndpoint(std::string logfile) { /* Create endpoint instance! */ try { @@ -155,5 +192,7 @@ namespace tp { TinyPhone* GetPhone(){ return tp::tpHttpServer->tinyPhone; } + + } diff --git a/tinyphone/config.cpp b/tinyphone/config.cpp index 0cc315c..8ce7697 100644 --- a/tinyphone/config.cpp +++ b/tinyphone/config.cpp @@ -77,7 +77,7 @@ namespace tp { std::cout << "Config Load From Primary Failed : Response Code " << remoteConfig.code << ", Content-Type: " << contentType << std::endl; std::string productVersion; #ifdef _DEBUG - productVersion = "HEAD"; + productVersion = "master"; #else GetProductVersion(productVersion); productVersion = "v" + productVersion; diff --git a/tinyphone/utils.cpp b/tinyphone/utils.cpp index 790c384..30c31ef 100644 --- a/tinyphone/utils.cpp +++ b/tinyphone/utils.cpp @@ -32,7 +32,7 @@ #include #include -#ifdef __APPLE__ +#ifndef _WIN32 #define _T(x) x #endif @@ -338,6 +338,16 @@ namespace tp { auto path = GetAppSupportDirectory(); boost::filesystem::path appDir(path); return appDir; + #else + const char * home = getenv ("HOME"); + if (home == NULL) { + throw std::invalid_argument("error: HOME environment variable not set."); + } + auto tiny_dir = string(home) + "/.tinyphone/"; + boost::filesystem::path appDir(tiny_dir); + if (!boost::filesystem::exists(appDir)) + boost::filesystem::create_directory(appDir); + return appDir; #endif } diff --git a/tinyphone/utils.h b/tinyphone/utils.h index 2c68402..ea3e44d 100644 --- a/tinyphone/utils.h +++ b/tinyphone/utils.h @@ -93,7 +93,7 @@ namespace tp { I random(I begin, I end) { const unsigned long n = std::distance(begin, end); - const unsigned long divisor = (RAND_MAX + 1) / n; + const unsigned long divisor = (RAND_MAX + 1l) / n; unsigned long k; do { k = std::rand() / divisor; } while (k >= n);