Updated directory structure and build steps
* seperate build-supplemental from build-version * version.cpp now included in cmake config, not directly imported * socket moved into its own directory * test_www removed from project
This commit is contained in:
parent
54d82b8c66
commit
fba87f3fbb
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -1,3 +1,2 @@
|
|||
anthracite
|
||||
src/error_pages/
|
||||
src/build/version.cpp
|
||||
build/
|
||||
build_supp/version.cpp
|
||||
|
|
|
@ -6,10 +6,17 @@ set(CMAKE_CXX_STANDARD 23)
|
|||
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
|
||||
|
||||
add_custom_target(build-version
|
||||
COMMAND cd ../build_supp && ./version.sh
|
||||
DEPENDS build_supp/version.txt
|
||||
COMMENT "Generated supplemental build files (version)"
|
||||
)
|
||||
|
||||
add_custom_target(build-supplemental
|
||||
COMMAND cd ../build_supp && ./version.sh && python3 ./error_gen.py
|
||||
COMMAND cd ../build_supp && python3 ./error_gen.py
|
||||
COMMAND cp -r ../www .
|
||||
DEPENDS build_supp/version.txt www/* build_supp/error_gen.py build-version
|
||||
COMMENT "Generated supplemental build files (default www dir + error pages)"
|
||||
)
|
||||
|
||||
add_custom_target(lint
|
||||
|
@ -20,10 +27,6 @@ add_custom_target(lint-fix
|
|||
COMMAND clang-tidy *.cpp -fix -fix-errors
|
||||
)
|
||||
|
||||
add_custom_target(format
|
||||
COMMAND clang-format *.cpp -i
|
||||
)
|
||||
|
||||
add_custom_target(build-docker
|
||||
COMMAND docker build .. -t anthracite
|
||||
)
|
||||
|
@ -34,15 +37,16 @@ add_custom_target(run
|
|||
WORKING_DIRECTORY ${CMAKE_PROJECT_DIR}
|
||||
)
|
||||
|
||||
FILE(GLOB SOURCES **/*.cpp)
|
||||
FILE(GLOB SOURCES src/**/*.cpp build_supp/version.cpp)
|
||||
|
||||
add_library(anthracite anthracite_main.cpp ${SOURCES})
|
||||
add_library(anthracite src/anthracite.cpp ${SOURCES})
|
||||
add_dependencies(anthracite build-version)
|
||||
|
||||
add_executable(anthracite-bin file_main.cpp)
|
||||
add_executable(anthracite-bin src/file_main.cpp)
|
||||
target_link_libraries(anthracite-bin anthracite)
|
||||
|
||||
add_executable(anthracite-api-bin api_main.cpp)
|
||||
target_link_libraries(anthracite-api-bin anthracite)
|
||||
|
||||
add_dependencies(anthracite-bin build-supplemental)
|
||||
add_dependencies(anthracite-bin anthracite)
|
||||
|
||||
add_executable(anthracite-api-bin src/api_main.cpp)
|
||||
target_link_libraries(anthracite-api-bin anthracite)
|
||||
|
|
@ -16,7 +16,7 @@ def generate_error_page(error_code, error_title):
|
|||
<h1>{error_code} - {error_title}</h1>
|
||||
<hr>
|
||||
<p>Anthracite/{version}</p>
|
||||
<p><small><a href="https://github.com/nickorlow/anthracite">This is Open Source Software</small></a></p>
|
||||
<p><small><a href="https://git.nickorlow.com/nickorlow/anthracite">This is Open Source Software</small></a></p>
|
||||
</center>
|
||||
</body>
|
||||
</html>"""
|
|
@ -1,3 +1,4 @@
|
|||
echo "#include <string>" > version.cpp
|
||||
echo "#include \"../src/version.hpp\"" >> version.cpp
|
||||
echo "const std::string ANTHRACITE_VERSION_STRING = \"$(cat version.txt)\";" >> version.cpp
|
||||
echo "const std::string ANTHRACITE_FULL_VERSION_STRING = \"Anthracite/$(cat version.txt)\";" >> version.cpp
|
1
build_supp/version.txt
Normal file
1
build_supp/version.txt
Normal file
|
@ -0,0 +1 @@
|
|||
0.3.0-dev
|
13
src/.gitignore
vendored
13
src/.gitignore
vendored
|
@ -1,13 +0,0 @@
|
|||
CMakeLists.txt.user
|
||||
anthracite-bin
|
||||
CMakeCache.txt
|
||||
CMakeFiles
|
||||
CMakeScripts
|
||||
Testing
|
||||
Makefile
|
||||
cmake_install.cmake
|
||||
install_manifest.txt
|
||||
compile_commands.json
|
||||
CTestTestfile.cmake
|
||||
_deps
|
||||
build/
|
|
@ -1,5 +1,5 @@
|
|||
#include "backends/file_backend.hpp"
|
||||
#include "./anthracite_main.hpp"
|
||||
#include "./anthracite.hpp"
|
||||
#include <condition_variable>
|
||||
#include <iostream>
|
||||
#include <mutex>
|
||||
|
@ -9,7 +9,7 @@
|
|||
#include <unistd.h>
|
||||
#include <span>
|
||||
#include "./log/log.hpp"
|
||||
#include "./socket.hpp"
|
||||
#include "./socket/socket.hpp"
|
||||
|
||||
using namespace anthracite;
|
||||
|
|
@ -1,5 +1,3 @@
|
|||
#pragma once
|
||||
|
||||
#include "backends/backend.hpp"
|
||||
|
||||
using namespace anthracite;
|
|
@ -1,4 +1,4 @@
|
|||
#include "./anthracite_main.hpp"
|
||||
#include "./anthracite.hpp"
|
||||
#include "backends/backend.hpp"
|
||||
#include "http/constants.hpp"
|
||||
#include <memory>
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
#include <string>
|
||||
const std::string ANTHRACITE_VERSION_STRING = "0.2.0";
|
||||
const std::string ANTHRACITE_FULL_VERSION_STRING = "Anthracite/0.2.0";
|
|
@ -1 +0,0 @@
|
|||
0.2.0
|
|
@ -1,4 +1,4 @@
|
|||
#include "./anthracite_main.hpp"
|
||||
#include "./anthracite.hpp"
|
||||
#include "backends/file_backend.hpp"
|
||||
|
||||
using namespace anthracite;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#include "response.hpp"
|
||||
#include "../build_supp/version.cpp"
|
||||
#include "../version.hpp"
|
||||
|
||||
namespace anthracite::http {
|
||||
|
||||
|
|
90
src/socket/socket.hpp
Normal file
90
src/socket/socket.hpp
Normal file
|
@ -0,0 +1,90 @@
|
|||
#include <arpa/inet.h>
|
||||
#include <array>
|
||||
#include <malloc.h>
|
||||
#include <netinet/in.h>
|
||||
#include <string>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <vector>
|
||||
|
||||
namespace anthracite::socket {
|
||||
|
||||
constexpr int MAX_QUEUE_LENGTH = 100;
|
||||
|
||||
class anthracite_socket {
|
||||
private:
|
||||
int server_socket;
|
||||
int client_socket {};
|
||||
std::string client_ip;
|
||||
struct sockaddr_in client_addr {};
|
||||
socklen_t client_addr_len {};
|
||||
static constexpr struct timeval timeout_tv {
|
||||
.tv_sec = 5, .tv_usec = 0
|
||||
};
|
||||
|
||||
public:
|
||||
anthracite_socket(int port, int max_queue = MAX_QUEUE_LENGTH)
|
||||
: server_socket(::socket(AF_INET, SOCK_STREAM, 0))
|
||||
, client_ip("")
|
||||
{
|
||||
struct sockaddr_in address {};
|
||||
address.sin_family = AF_INET;
|
||||
address.sin_port = htons(port);
|
||||
address.sin_addr.s_addr = INADDR_ANY;
|
||||
|
||||
int reuse_opt = 1;
|
||||
setsockopt(server_socket, SOL_SOCKET, SO_REUSEADDR, &reuse_opt, sizeof(reuse_opt));
|
||||
bind(server_socket, reinterpret_cast<struct sockaddr*>(&address), sizeof(address));
|
||||
|
||||
listen(server_socket, max_queue);
|
||||
}
|
||||
|
||||
void wait_for_conn()
|
||||
{
|
||||
client_ip = "";
|
||||
client_socket = accept(server_socket, reinterpret_cast<struct sockaddr*>(&client_addr), &client_addr_len);
|
||||
std::array<char, INET_ADDRSTRLEN> ip_str { 0 };
|
||||
inet_ntop(AF_INET, &client_addr.sin_addr, ip_str.data(), INET_ADDRSTRLEN);
|
||||
client_ip = std::string(ip_str.data());
|
||||
}
|
||||
|
||||
const std::string& get_client_ip()
|
||||
{
|
||||
return client_ip;
|
||||
}
|
||||
|
||||
void close_conn()
|
||||
{
|
||||
close(client_socket);
|
||||
client_socket = -1;
|
||||
}
|
||||
|
||||
void send_message(std::string& msg)
|
||||
{
|
||||
if (client_socket == -1) {
|
||||
return;
|
||||
}
|
||||
send(client_socket, &msg[0], msg.length(), 0);
|
||||
}
|
||||
|
||||
std::string recv_message(int buffer_size)
|
||||
{
|
||||
if (client_socket == -1) {
|
||||
return "";
|
||||
}
|
||||
|
||||
setsockopt(client_socket, SOL_SOCKET, SO_RCVTIMEO, &timeout_tv, sizeof timeout_tv);
|
||||
std::vector<char> response(buffer_size + 1);
|
||||
ssize_t result = recv(client_socket, response.data(), buffer_size + 1, 0);
|
||||
|
||||
if (result < 1) {
|
||||
return "";
|
||||
}
|
||||
|
||||
response[buffer_size] = '\0';
|
||||
return { response.data() };
|
||||
}
|
||||
};
|
||||
|
||||
};
|
Binary file not shown.
Before Width: | Height: | Size: 496 KiB |
Binary file not shown.
Before Width: | Height: | Size: 319 B |
Binary file not shown.
Before Width: | Height: | Size: 3.6 KiB |
Binary file not shown.
Before Width: | Height: | Size: 38 KiB |
Binary file not shown.
Before Width: | Height: | Size: 42 KiB |
|
@ -1,18 +0,0 @@
|
|||
.cool-style {
|
||||
background: linear-gradient(to right, #ef5350, #f48fb1, #7e57c2, #2196f3, #26c6da, #43a047, #eeff41, #f9a825, #ff5722);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
}
|
||||
|
||||
.content {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.content img {
|
||||
max-width: 100%;
|
||||
height: auto;
|
||||
margin: 10px;
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Anthracite</title>
|
||||
<link rel="icon" type="image/x-icon" href="/images/favicon_anim.ico">
|
||||
<link rel="stylesheet" href="test.css">
|
||||
</head>
|
||||
<body>
|
||||
<center>
|
||||
<h1 class="cool-style">Test Page!</h1>
|
||||
<h2>Dogs</h2>
|
||||
<div class="content">
|
||||
<img src="/images/tini.png" alt="A border collie" />
|
||||
<img src="/images/lola.jpeg" alt="A border collie" />
|
||||
<img src="/images/emma.bmp" alt="A corgi" />
|
||||
</div>
|
||||
<h2>Trains</h2>
|
||||
<div>
|
||||
<video controls>
|
||||
<source src="videos/train_vid.mp4" />
|
||||
</video>
|
||||
</div>
|
||||
</center>
|
||||
</body>
|
||||
</html>
|
Binary file not shown.
6
src/version.hpp
Normal file
6
src/version.hpp
Normal file
|
@ -0,0 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
extern const std::string ANTHRACITE_VERSION_STRING;
|
||||
extern const std::string ANTHRACITE_FULL_VERSION_STRING;
|
|
@ -1,9 +0,0 @@
|
|||
<head>
|
||||
<title>Anthracite</title>
|
||||
<link rel="icon" type="image/x-icon" href="/images/favicon.ico">
|
||||
</head>
|
||||
<center>
|
||||
<h1>Anthracite is Running!</h1>
|
||||
<p>If you are seeing this page, then Anthracite is configured correctly!</p>
|
||||
<p>Add files to the "www" directory to begin serving your website.</p>
|
||||
</center>
|
Loading…
Reference in a new issue