From 47195967c28ec467a23c826b12afcbe9051ef81f Mon Sep 17 00:00:00 2001 From: Tropby Date: Tue, 27 Feb 2024 20:12:07 +0100 Subject: [PATCH 1/5] Removed GUI from compilation. --- CMakeLists.txt | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 84b1210..5078a56 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,6 @@ project(EBCppExamples VERSION 0.1 LANGUAGES CXX) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/../bin) # Configure and Include EBCpp -set(EBCPP_USE_GUI On) # On/Off - Using the windows gui functions (only for testing) set(EBCPP_USE_SSL Off) # On/Off - Using openssl for ssl sockets and https set(EBCPP_USE_SSL_STATIC Off) # On/Off - Activate static linking of openssl into your application (see openssl license) set(EBCPP_USE_SQLITE Off) # On/Off - Using sqlite in your application (static linked) @@ -94,30 +93,6 @@ if(WIN32) else() target_link_libraries(EBCppExampleSerialPort pthread) endif() - - # Compile EBCppExampleGui - add_executable(EBCppExampleGui examples/ExampleGui.cpp) - if(WIN32) - target_link_libraries(EBCppExampleGui gdiplus -Wl,-subsystem,windows) - else() - target_link_libraries(EBCppExampleGui pthread) - endif() - - # Compile EBCppExampleImage - add_executable(EBCppExampleGuiImage examples/ExampleGuiImage.cpp) - if(WIN32) - target_link_libraries(EBCppExampleGuiImage gdiplus -Wl,-subsystem,windows) - else() - target_link_libraries(EBCppExampleGui pthread) - endif() - - # Compile EBCppExampleGuiLayout - add_executable(EBCppExampleGuiLayout examples/ExampleGuiLayout.cpp) - if(WIN32) - target_link_libraries(EBCppExampleGuiLayout gdiplus -Wl,-subsystem,windows) - else() - target_link_libraries(EBCppExampleGuiLayout pthread) - endif() endif() find_package(OpenSSL) From 77ed1f351e8b0954a272c411d912859a39b9d472 Mon Sep 17 00:00:00 2001 From: Carsten Date: Wed, 28 Feb 2024 19:16:34 +0100 Subject: [PATCH 2/5] Create codeql.yml --- .github/workflows/codeql.yml | 84 ++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 .github/workflows/codeql.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..f7f2b46 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,84 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + schedule: + - cron: '27 5 * * 1' + +jobs: + analyze: + name: Analyze + # Runner size impacts CodeQL analysis time. To learn more, please see: + # - https://gh.io/recommended-hardware-resources-for-running-codeql + # - https://gh.io/supported-runners-and-hardware-resources + # - https://gh.io/using-larger-runners + # Consider using larger runners for possible analysis time improvements. + runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} + timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} + permissions: + # required for all workflows + security-events: write + + # only required for workflows in private repositories + actions: read + contents: read + + strategy: + fail-fast: false + matrix: + language: [ 'c-cpp' ] + # CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ] + # Use only 'java-kotlin' to analyze code written in Java, Kotlin or both + # Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: ${{ matrix.language }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + + # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). + # If this step fails, then you should remove it and run the build manually (see below) + - name: Autobuild + uses: github/codeql-action/autobuild@v3 + + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + + # If the Autobuild fails above, remove it and uncomment the following three lines. + # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. + + # - run: | + # echo "Run, Build Application using script" + # ./location_of_script_within_repo/buildscript.sh + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: "/language:${{matrix.language}}" From ab4e26a1757bae4207ad3ae3fa16438deb94663e Mon Sep 17 00:00:00 2001 From: Carsten Date: Wed, 28 Feb 2024 19:23:23 +0100 Subject: [PATCH 3/5] Delete .github/workflows/codeql.yml --- .github/workflows/codeql.yml | 84 ------------------------------------ 1 file changed, 84 deletions(-) delete mode 100644 .github/workflows/codeql.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml deleted file mode 100644 index f7f2b46..0000000 --- a/.github/workflows/codeql.yml +++ /dev/null @@ -1,84 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "CodeQL" - -on: - push: - branches: [ "master" ] - pull_request: - branches: [ "master" ] - schedule: - - cron: '27 5 * * 1' - -jobs: - analyze: - name: Analyze - # Runner size impacts CodeQL analysis time. To learn more, please see: - # - https://gh.io/recommended-hardware-resources-for-running-codeql - # - https://gh.io/supported-runners-and-hardware-resources - # - https://gh.io/using-larger-runners - # Consider using larger runners for possible analysis time improvements. - runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} - timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} - permissions: - # required for all workflows - security-events: write - - # only required for workflows in private repositories - actions: read - contents: read - - strategy: - fail-fast: false - matrix: - language: [ 'c-cpp' ] - # CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ] - # Use only 'java-kotlin' to analyze code written in Java, Kotlin or both - # Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both - # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v3 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - - # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs - # queries: security-extended,security-and-quality - - - # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v3 - - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun - - # If the Autobuild fails above, remove it and uncomment the following three lines. - # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. - - # - run: | - # echo "Run, Build Application using script" - # ./location_of_script_within_repo/buildscript.sh - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v3 - with: - category: "/language:${{matrix.language}}" From cb7b7719e263b677b435d1f24d369acccc681260 Mon Sep 17 00:00:00 2001 From: Tropby Date: Wed, 28 Feb 2024 20:42:58 +0100 Subject: [PATCH 4/5] Fixed some problems with ICMP. --- src/socket/raw/EBICMP.hpp | 56 +++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/src/socket/raw/EBICMP.hpp b/src/socket/raw/EBICMP.hpp index dbf41e1..5e696b9 100644 --- a/src/socket/raw/EBICMP.hpp +++ b/src/socket/raw/EBICMP.hpp @@ -30,6 +30,12 @@ * Author: Carsten (Tropby) */ +/** + * ATTENTION: You need to add the follwoing libs to the target: + * target_link_libraries(TARGET -lws2_32 -liphlpapi) + * + */ + #pragma once #include @@ -37,11 +43,8 @@ #ifdef __WIN32__ #include -#endif - -#ifdef __WIN32__ -#include #include +#include #include #else #error NOT IMPLEMENTED FOR UNIX @@ -65,6 +68,17 @@ class EBICMP : public EBObject { } + ~EBICMP() + { + if( thread ) + { + if( thread->joinable() ) + { + thread->join(); + } + } + } + void setDestination(EBUrl destination) { this->destination = destination; @@ -157,19 +171,39 @@ class EBICMP : public EBObject result.roundtrip = pEchoReply->RoundTripTime; result.status = pEchoReply->Status; - WCHAR buffer[128]; - char str[128]; - long unsigned int size = 128; - GetIpErrorString(result.status, buffer, &size); - wcstombs(str, buffer, 128); - result.resultString = str; + if( result.status != IP_SUCCESS ) + { + WCHAR buffer[128]; + char str[128]; + long unsigned int size = 128; + GetIpErrorString(result.status, buffer, &size); + wcstombs(str, buffer, 128); + result.resultString = str; + } + else + { + result.resultString = "Okay"; + } running = false; EB_EMIT_WITH_ARGS(finished, result); } else { - lastError = EBString() + "Timeout! [Code: " + EBUtils::intToStr(GetLastError()) + "]"; + DWORD errorMessageID = ::GetLastError(); + if(errorMessageID != 0) + { + LPSTR messageBuffer = nullptr; + size_t size = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, errorMessageID, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&messageBuffer, 0, NULL); + + lastError = EBString() + "Timeout! [Code: " + EBString(messageBuffer, size) + "]"; + LocalFree(messageBuffer); + } + else + { + lastError = "NO ERROR? " + EBUtils::intToStr(dwRetVal); + } running = false; EB_EMIT(error); } From 93d957f96c4789b32ad92f7a91dbf146b8023208 Mon Sep 17 00:00:00 2001 From: Tropby Date: Thu, 29 Feb 2024 13:35:35 +0100 Subject: [PATCH 5/5] Added "containsArguiment" to EBApplication. Set roundtriptime to "-1" on error in EBICMP. Set version of EBXmlDocument to "1.0". Added setter/getter for root element to EBXmlDocument. --- src/EBApplication.hpp | 5 +++++ src/socket/raw/EBICMP.hpp | 1 + src/xml/EBXmlDocument.hpp | 14 ++++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/EBApplication.hpp b/src/EBApplication.hpp index b82bd86..b494973 100644 --- a/src/EBApplication.hpp +++ b/src/EBApplication.hpp @@ -72,6 +72,11 @@ class EBApplication : public EBObject } } + static bool containsArgument( const EBString& argument ) + { + return arguments.contains(argument); + } + static EBString getArgument( int index ) { return arguments.get(index); diff --git a/src/socket/raw/EBICMP.hpp b/src/socket/raw/EBICMP.hpp index 5e696b9..3590965 100644 --- a/src/socket/raw/EBICMP.hpp +++ b/src/socket/raw/EBICMP.hpp @@ -179,6 +179,7 @@ class EBICMP : public EBObject GetIpErrorString(result.status, buffer, &size); wcstombs(str, buffer, 128); result.resultString = str; + result.roundtrip = -1; } else { diff --git a/src/xml/EBXmlDocument.hpp b/src/xml/EBXmlDocument.hpp index 0156a03..7a80892 100644 --- a/src/xml/EBXmlDocument.hpp +++ b/src/xml/EBXmlDocument.hpp @@ -47,7 +47,7 @@ namespace EBCpp class EBXmlDocument : public EBObject { public: - EBXmlDocument() + EBXmlDocument() : version("1.0") { root = nullptr; } @@ -132,7 +132,17 @@ class EBXmlDocument : public EBObject const EBString getStandalone() const { return standalone; - } + } + + void setRootElement(const EBPtr element) + { + root = element; + } + + const EBPtr getRootElement() const + { + return root; + } private: