Skip to content

Commit 3cc51fe

Browse files
committed
intial code upload
1 parent ad2e138 commit 3cc51fe

44 files changed

Lines changed: 13612 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
cmake_minimum_required(VERSION 3.16)
2+
3+
project(clienthttp)
4+
5+
# Set default architecture if not specified
6+
if(NOT DEFINED TARGET_ARCH)
7+
set(TARGET_ARCH "x64")
8+
endif()
9+
10+
# Set architecture-specific flags
11+
if(${TARGET_ARCH} STREQUAL "x86")
12+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32")
13+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32")
14+
elseif(${TARGET_ARCH} STREQUAL "x64")
15+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64")
16+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m64")
17+
else()
18+
message(FATAL_ERROR "Unsupported architecture: ${TARGET_ARCH}")
19+
endif()
20+
21+
# Enable new DTAGs to use RUNPATH instead of RPATH
22+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--enable-new-dtags")
23+
24+
# Set the build RUNPATH (used during runtime time)
25+
set(CMAKE_BUILD_RPATH "$ORIGIN;$ORIGIN/lib")
26+
27+
# Set the build type to Release
28+
set(CMAKE_BUILD_TYPE "Release")
29+
30+
# Set source and header file directories
31+
set(SOURCE_DIR src)
32+
set(HEADER_DIR include)
33+
34+
# Add your source files
35+
set(SOURCES
36+
${SOURCE_DIR}/main.cpp
37+
${SOURCE_DIR}/base64.cpp
38+
${SOURCE_DIR}/http.cpp
39+
${SOURCE_DIR}/json.cpp
40+
${SOURCE_DIR}/utilities.cpp
41+
${SOURCE_DIR}/operations.cpp
42+
)
43+
44+
# Optionally, add headers for IDEs or reference
45+
set(HEADERS
46+
${HEADER_DIR}/base64.h
47+
${HEADER_DIR}/http.h
48+
${HEADER_DIR}/json.h
49+
${HEADER_DIR}/utilities.h
50+
${HEADER_DIR}/operations.h
51+
)
52+
53+
# Create the executable (using only source files)
54+
add_executable(clienthttp ${SOURCES})
55+
56+
# Set the C++17 standard
57+
target_compile_features(clienthttp PRIVATE cxx_std_17)
58+
59+
# Include the header directory
60+
target_include_directories(clienthttp PRIVATE ${HEADER_DIR})
61+
62+
# Link the curl library
63+
find_package(CURL REQUIRED)
64+
target_link_libraries(clienthttp PRIVATE CURL::libcurl)
65+
66+
# Link the pthread library
67+
find_package(Threads REQUIRED)
68+
target_link_libraries(clienthttp PRIVATE Threads::Threads)
69+
70+
# Link against the stdc++fs library
71+
target_link_libraries(clienthttp PRIVATE stdc++fs)
72+
73+
# Set linker flags to disable symbol generation
74+
set_target_properties(clienthttp PROPERTIES LINK_FLAGS_RELEASE "-s")
75+
76+
# Set compiler flags for size optimization
77+
target_compile_options(clienthttp PRIVATE -Os)

include/base64.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
3+
//#ifdef MYDLL_EXPORTS
4+
///*Enabled as "export" while compiling the dll project*/
5+
//#define DLLEXPORT __declspec(dllexport)
6+
//#else
7+
///*Enabled as "import" in the Client side for using already created dll file*/
8+
//#define DLLEXPORT __declspec(dllimport)
9+
//#endif
10+
11+
#include <string>
12+
13+
/* =================================== Public API's =================================== */
14+
#ifdef __cplusplus // If used by C++ code,
15+
16+
std::string base64_encode(unsigned char const*, unsigned int len);
17+
std::string base64_decode(std::string const& s);
18+
//std::string encodeBase64(const std::string& data, size_t size);
19+
//std::string decodeBase64(const std::string& data, size_t size);
20+
21+
#endif

include/http.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) Nouman Tajik [github.com/tajiknomi]
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in all
11+
// copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
// SOFTWARE.
20+
21+
22+
23+
#pragma once
24+
25+
#include <string>
26+
#include "base64.h"
27+
28+
#define READ_BUFFER_SIZE 1024 // Receiving Buffer Size in bytes
29+
#define TIMEOUT_SEC 3 // Wait period for incoming data in seconds
30+
31+
std::wstring httpPost(const std::wstring &hostname, const std::wstring &request);

include/json.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) Nouman Tajik [github.com/tajiknomi]
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in all
11+
// copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
// SOFTWARE.
20+
21+
22+
23+
#pragma once
24+
25+
#include <vector>
26+
27+
// data -----> json
28+
std::wstring to_json(const std::vector<std::wstring>& data);
29+
30+
// json -----> data
31+
std::vector<std::wstring> from_json(const std::wstring& jsonData);
32+
33+
// Extract <value> from json using <key>
34+
std::wstring json_ExtractValue(const std::wstring& jsonData, const std::wstring& key);
35+
36+
// Insert a key-value pair into an existing JSON string
37+
std::wstring json_AppendKeyValue(const std::wstring& jsonData, const std::wstring& key, const std::wstring& value);

include/operations.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) Nouman Tajik [github.com/tajiknomi]
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in all
11+
// copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
// SOFTWARE.
20+
21+
22+
23+
#pragma once
24+
#include <string>
25+
#include <queue>
26+
#include <mutex>
27+
28+
extern std::queue<std::wstring> responseQueue;
29+
extern std::mutex responseQueueMutex;
30+
extern std::queue<std::wstring> jobQueue;
31+
extern std::mutex jobQueueMutex;
32+
extern std::wstring jsonSysInfo;
33+
34+
bool isJobAvailable(const std::wstring &replyFromServer);
35+
void startJob();

0 commit comments

Comments
 (0)