initial
This commit is contained in:
parent
65bd8192d4
commit
ceae213b03
@ -1,7 +1,22 @@
|
|||||||
cmake_minimum_required(VERSION 3.0)
|
cmake_minimum_required(VERSION 3.0)
|
||||||
|
|
||||||
project(birdbadge)
|
project(birdbadge
|
||||||
|
VERSION 0.0.1
|
||||||
|
DESCRIPTION "Bird Badge"
|
||||||
|
LANGUAGES CXX
|
||||||
|
)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
find_package(PkgConfig REQUIRED)
|
||||||
|
pkg_check_modules(FCGI fcgi)
|
||||||
|
|
||||||
add_executable(birdbadge main.cpp)
|
add_executable(birdbadge main.cpp)
|
||||||
|
|
||||||
|
target_link_libraries(birdbadge
|
||||||
|
fcgi
|
||||||
|
fcgi++
|
||||||
|
)
|
||||||
|
|
||||||
install(TARGETS birdbadge RUNTIME DESTINATION bin)
|
install(TARGETS birdbadge RUNTIME DESTINATION bin)
|
||||||
|
47
main.cpp
47
main.cpp
@ -1,6 +1,47 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <string>
|
||||||
|
#include <fcgio.h>
|
||||||
|
#include <fcgiapp.h>
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
#include <unistd.h>
|
||||||
std::cout << "Hello, world!" << std::endl;
|
|
||||||
return 0;
|
constexpr static const char* GET("GET");
|
||||||
|
|
||||||
|
constexpr static const char* REQUEST_METHOD("REQUEST_METHOD");
|
||||||
|
constexpr static const char* SCRIPT_NAME("SCRIPT_NAME");
|
||||||
|
|
||||||
|
constexpr static const char* status405("Status: 405 Method Not Allowed");
|
||||||
|
constexpr static const char* contentTypeHtml("Content-type: text/html");
|
||||||
|
|
||||||
|
constexpr static const char* headerEnd("\n\n");
|
||||||
|
|
||||||
|
void handleRequest(FCGX_Request& request) {
|
||||||
|
fcgi_streambuf cin_fcgi_streambuf(request.in);
|
||||||
|
fcgi_streambuf cout_fcgi_streambuf(request.out);
|
||||||
|
fcgi_streambuf cerr_fcgi_streambuf(request.err);
|
||||||
|
std::ostream os{&cout_fcgi_streambuf};
|
||||||
|
std::ostream errs{&cerr_fcgi_streambuf};
|
||||||
|
std::istream is{&cin_fcgi_streambuf};
|
||||||
|
|
||||||
|
std::string requestMethod(FCGX_GetParam(REQUEST_METHOD, request.envp));
|
||||||
|
if (requestMethod != GET) {
|
||||||
|
os << status405;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string scriptName{FCGX_GetParam(SCRIPT_NAME, request.envp)};
|
||||||
|
os << contentTypeHtml;
|
||||||
|
os << headerEnd;
|
||||||
|
os << scriptName << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
FCGX_Request request;
|
||||||
|
|
||||||
|
FCGX_Init();
|
||||||
|
FCGX_InitRequest(&request, 0, 0);
|
||||||
|
|
||||||
|
while (FCGX_Accept_r(&request) == 0) {
|
||||||
|
handleRequest(request);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user