summaryrefslogtreecommitdiffhomepage
path: root/plugins/fcgi/fcgi.h
blob: 167a3565d74afbcb6bf084e8b257299c91b204e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#pragma once

#include "../../plugin_interface.h"

#include "socket.h"

#include <boost/asio.hpp>

#include <cstdint>
#include <mutex>
#include <set>

// automatically reserves ID, and releases it via RAII
class FCGI_ID_Guard
{
 FCGI_ID& m_fcgi_id;
 uint16_t m_id;

public:
 FCGI_ID_Guard(FCGI_ID& fcgi_id): m_fcgi_id(fcgi_id), m_id(fcgi_id.getID())
 {
 }

 ~FCGI_ID_Guard()
 {
  m_fcgi_id.putID(m_id);
 }

 uint16_t getID() const { return m_id; }
};

struct FCGIContext;

class fcgi_plugin: public webserver_plugin_interface 
{
 SocketFactory m_socket_factory;

 std::unordered_map<std::string, std::shared_ptr<Socket>> m_sockets;

public:
 fcgi_plugin();
 ~fcgi_plugin();
 
 std::string name() override;
 std::string generate_page(
  std::function<std::string(const std::string& key)>& GetServerParam,
  std::function<std::string(const std::string& key)>& GetRequestParam, // request including body (POST...)
  std::function<void(const std::string& key, const std::string& value)>& SetResponseHeader // to be added to result string
 ) override;
 
 bool has_own_authentication() override;

 std::string fcgiQuery(FCGIContext& context);
};

extern "C" BOOST_SYMBOL_EXPORT fcgi_plugin webserver_plugin;
fcgi_plugin webserver_plugin;