chomik 0.2.1
experimental and minimalistic programming language

My name is Pawel Biernacki.
I am a software engineer.
This site is my hobby project.

Loading...
Searching...
No Matches
http_chomik.h
Go to the documentation of this file.
1#ifndef HTTP_CHOMIK_H
2#define HTTP_CHOMIK_H
3
4#include "chomik.h"
5#include <regex>
6
7namespace http_chomik
8{
13 {
14 public:
15 virtual void create_predefined_streams() override;
16
17 virtual bool get_can_create_files() const override final { return false; }
18 };
19
20 class server;
21
23 {
24 protected:
25 virtual void create_a_new_server(std::unique_ptr<server> & target, int sock) = 0;
26
31 virtual void process(const std::string & uri, std::ostream & message_stream, std::string & response_type, std::unique_ptr<http_chomik::server> & my_server);
32
33 public:
34 static void do_processing_client(int sock, wrapper_base & my_wrapper);
35 };
36
40 class server
41 {
42 private:
43 int sock;
44
45 protected:
50 virtual void add_html_head_content(std::ostream & message_stream);
51
55 virtual void add_html_default_chomik_code(std::ostream & message_stream);
56
60 virtual void add_html_body(std::ostream & message_stream);
61
65 virtual void add_html_body_for_incorrect_uri(std::ostream & message_stream);
66
70 virtual void add_html_body_for_code(std::ostream & message_stream, const std::string & decoded_code, std::stringstream & error_stream,
71 std::stringstream & error_stream2);
72
76 void add_html_for_program_output(std::istream & source, std::ostream & message_stream);
77
78
82 virtual void create_a_new_machine(std::unique_ptr<machine> & target);
83
84
85 public:
86 server(int s): sock{s} {}
88 void read_data(std::ostream & input_buffer_stream);
89 void handle_main(std::ostream & message_stream);
90 void handle_incorrect_uri(std::ostream & message_stream);
91 void handle_code(std::ostream & message_stream, std::smatch & m);
92 void handle_chomik_image(std::ostream & message_stream);
93 void handle_stylesheet(std::ostream & message_stream);
94
95 void send_message(const std::string & message);
96
97 static void do_processing(int my_port, wrapper_base & my_wrapper);
98 };
99
104 template <typename SERVER_CLASS> class wrapper: public wrapper_base
105 {
106 protected:
107 virtual void create_a_new_server(std::unique_ptr<server> & target, int sock) override
108 {
109 target = std::move(std::make_unique<SERVER_CLASS>(sock));
110 }
111 public:
112
113 };
114
115}
116
117#define HTTP_CHOMIK_PRODUCTION
118
119#ifdef HTTP_CHOMIK_PRODUCTION
120#define HTTP_CHOMIK_LOG_ERROR(X) \
121{ \
122 std::stringstream s; \
123 s << X; \
124 syslog (LOG_PERROR, s.str().c_str()); \
125}
126#define HTTP_CHOMIK_LOG_NOTICE(X) \
127{ \
128 std::stringstream s; \
129 s << X; \
130 syslog (LOG_NOTICE, s.str().c_str()); \
131}
132#else
133#define HTTP_CHOMIK_LOG_ERROR(X) \
134{ \
135 std::stringstream s; \
136 s << X; \
137 std::cerr << s.str() << "\n"; \
138}
139#define HTTP_CHOMIK_LOG_NOTICE(X) \
140{ \
141 std::stringstream s; \
142 s << X; \
143 std::cout << s.str() << "\n"; \
144}
145#endif
146
147
148#endif
149
Definition chomik.h:3425
Definition http_chomik.h:13
virtual void create_predefined_streams() override
virtual bool get_can_create_files() const override final
Definition http_chomik.h:17
Definition http_chomik.h:41
virtual void create_a_new_machine(std::unique_ptr< machine > &target)
void handle_main(std::ostream &message_stream)
virtual void add_html_body_for_incorrect_uri(std::ostream &message_stream)
void send_message(const std::string &message)
server(int s)
Definition http_chomik.h:86
virtual void add_html_head_content(std::ostream &message_stream)
static void do_processing(int my_port, wrapper_base &my_wrapper)
virtual void add_html_body_for_code(std::ostream &message_stream, const std::string &decoded_code, std::stringstream &error_stream, std::stringstream &error_stream2)
virtual void add_html_default_chomik_code(std::ostream &message_stream)
void read_data(std::ostream &input_buffer_stream)
void handle_code(std::ostream &message_stream, std::smatch &m)
void handle_chomik_image(std::ostream &message_stream)
void handle_incorrect_uri(std::ostream &message_stream)
virtual void add_html_body(std::ostream &message_stream)
void add_html_for_program_output(std::istream &source, std::ostream &message_stream)
void handle_stylesheet(std::ostream &message_stream)
Definition http_chomik.h:23
virtual void create_a_new_server(std::unique_ptr< server > &target, int sock)=0
virtual void process(const std::string &uri, std::ostream &message_stream, std::string &response_type, std::unique_ptr< http_chomik::server > &my_server)
static void do_processing_client(int sock, wrapper_base &my_wrapper)
Definition http_chomik.h:105
virtual void create_a_new_server(std::unique_ptr< server > &target, int sock) override
Definition http_chomik.h:107
Definition http_chomik.h:8

copyright by Pawel Biernacki

Vantaa 2022