Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
43da7fddf9 |
@ -44,6 +44,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="chat-renunciation-win" class="popup-window">
|
<div id="chat-renunciation-win" class="popup-window">
|
||||||
|
<!-- header will actually be rewritten before showing the window to include chat nickname -->
|
||||||
<h1 id="chat-renunciation-win-title" class="popup-window-msg">||||||||||</h1>
|
<h1 id="chat-renunciation-win-title" class="popup-window-msg">||||||||||</h1>
|
||||||
<button class="popup-window-btn-yes" id="chat-renunciation-win-yes">{%w pres.list-rooms.yes-leave %}</button>
|
<button class="popup-window-btn-yes" id="chat-renunciation-win-yes">{%w pres.list-rooms.yes-leave %}</button>
|
||||||
<button class="popup-window-btn-no" id="chat-renunciation-win-no">{%w pres.list-rooms.no-leave %}</button>
|
<button class="popup-window-btn-no" id="chat-renunciation-win-no">{%w pres.list-rooms.no-leave %}</button>
|
||||||
|
@ -1,166 +1,51 @@
|
|||||||
/* Общие стили */
|
|
||||||
body {
|
|
||||||
font-family: 'Roboto', sans-serif;
|
|
||||||
background-color: #f7f9fc;
|
|
||||||
color: #333;
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Панель навигации */
|
|
||||||
.panel {
|
|
||||||
background-color: #007bff;
|
|
||||||
padding: 10px;
|
|
||||||
color: white;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
.panel-thing {
|
|
||||||
margin-right: 20px;
|
|
||||||
text-decoration: none;
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
.panel-header-txt {
|
|
||||||
font-size: 18px;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Стили динамических блоков */
|
|
||||||
.dynamic-block-list {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
align-items: center;
|
|
||||||
padding: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.dynamic-block-list-el-container {
|
|
||||||
width: 100%;
|
|
||||||
max-width: 600px;
|
|
||||||
margin-top: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Кнопка добавления */
|
|
||||||
.button-add {
|
|
||||||
width: 50px;
|
|
||||||
height: 50px;
|
|
||||||
cursor: pointer;
|
|
||||||
transition: transform 0.2s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.button-add:hover {
|
|
||||||
transform: scale(1.1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Всплывающие окна */
|
|
||||||
.popup-window {
|
|
||||||
background-color: white;
|
|
||||||
border-radius: 8px;
|
|
||||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
|
|
||||||
padding: 20px;
|
|
||||||
max-width: 500px;
|
|
||||||
margin: 0 auto;
|
|
||||||
}
|
|
||||||
|
|
||||||
.popup-window-msg {
|
|
||||||
font-size: 20px;
|
|
||||||
margin-bottom: 15px;
|
|
||||||
color: #333;
|
|
||||||
}
|
|
||||||
|
|
||||||
.popup-window-btn-yes, .popup-window-btn-no {
|
|
||||||
padding: 10px 20px;
|
|
||||||
border: none;
|
|
||||||
border-radius: 5px;
|
|
||||||
font-size: 16px;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.popup-window-btn-yes {
|
|
||||||
background-color: #28a745;
|
|
||||||
color: white;
|
|
||||||
margin-right: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.popup-window-btn-no {
|
|
||||||
background-color: #dc3545;
|
|
||||||
color: white;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Таблица ввода */
|
|
||||||
table.id-str-input-table {
|
|
||||||
width: 100%;
|
|
||||||
border-collapse: collapse;
|
|
||||||
margin-bottom: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.id-str-input-td1, .id-str-input-td2 {
|
|
||||||
border: none;
|
|
||||||
padding: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.id-str-input-td1 {
|
|
||||||
text-align: left;
|
|
||||||
padding-right: 10px;
|
|
||||||
font-weight: bold;
|
|
||||||
color: #555;
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
.id-str-input-td2 {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.one-line-input {
|
|
||||||
width: 100%;
|
|
||||||
padding: 8px 12px;
|
|
||||||
border: 1px solid #ccc;
|
|
||||||
border-radius: 4px;
|
|
||||||
font-size: 14px;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Стили комнат */
|
|
||||||
.CL-my-chat-box {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
position: relative;
|
|
||||||
padding: 10px;
|
|
||||||
background-color: #e0f7fa;
|
|
||||||
border-radius: 8px;
|
|
||||||
margin-bottom: 10px;
|
|
||||||
align-items: center;
|
|
||||||
min-height: 40px;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Текст внутри блока комнаты */
|
|
||||||
.CL-my-chat-box-nickname, .CL-my-chat-box-name, .CL-my-chat-box-my-role {
|
|
||||||
margin-left: 8px;
|
|
||||||
justify-self: flex-start;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Крестик в правом верхнем углу */
|
|
||||||
.CL-my-chat-box-leave-btn {
|
|
||||||
position: absolute;
|
|
||||||
top: 8px;
|
|
||||||
right: 8px;
|
|
||||||
width: 16px;
|
|
||||||
height: 16px;
|
|
||||||
background: url('/assets/img/close.svg') no-repeat center;
|
|
||||||
background-size: cover;
|
|
||||||
cursor: pointer;
|
|
||||||
border: none;
|
|
||||||
transition: transform 0.2s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.CL-my-chat-box-leave-btn:hover {
|
|
||||||
transform: scale(1.2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Дизайн списка комнат остается таким же */
|
|
||||||
#CL-bacbe {
|
#CL-bacbe {
|
||||||
margin-top: 6px;
|
margin-top: 6px;
|
||||||
margin-bottom: 4px;
|
margin-bottom: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.CL-my-chat-box {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CL-my-chat-box-nickname {
|
||||||
|
margin-left: 8px;
|
||||||
|
justify-self: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CL-my-chat-box-name {
|
||||||
|
margin-left: 14px;
|
||||||
|
justify-self: flex-start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CL-my-chat-box-my-role {
|
||||||
|
margin-left: auto;
|
||||||
|
justify-self: flex-end;
|
||||||
|
}
|
||||||
|
|
||||||
|
.CL-my-chat-box-leave-btn {
|
||||||
|
margin-left: 10px;
|
||||||
|
margin-right: 8px;
|
||||||
|
justify-self: flex-end;
|
||||||
|
width: 16px;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The morbid thing */
|
||||||
|
table.id-str-input-table {
|
||||||
|
width: 100%;
|
||||||
|
border-collapse: collapse; /* Combine borders */
|
||||||
|
}
|
||||||
|
.id-str-input-td1, .id-str-input-td2 {
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
.id-str-input-td1 {
|
||||||
|
text-align: left;
|
||||||
|
padding-right: 5px;
|
||||||
|
white-space: nowrap; /* Prevent text wrap, keeping it in one line */
|
||||||
|
overflow: hidden; /* Hide overflow content */
|
||||||
|
text-overflow: ellipsis; /* Show ellipsis for overflowing text */
|
||||||
|
}
|
||||||
|
.id-str-input-td2 {
|
||||||
|
width: 100%;
|
||||||
|
}
|
@ -95,7 +95,7 @@ struct CAWebChat {
|
|||||||
"thread_synchronization.h",
|
"thread_synchronization.h",
|
||||||
"os_utils.h",
|
"os_utils.h",
|
||||||
"connecting_assets/static_asset_manager.h",
|
"connecting_assets/static_asset_manager.h",
|
||||||
"http_structures/client_request.h",
|
"http_structures/messages.h",
|
||||||
"http_structures/cookies.h",
|
"http_structures/cookies.h",
|
||||||
"http_structures/response_gen.h",
|
"http_structures/response_gen.h",
|
||||||
"http_structures/accept_language.h",
|
"http_structures/accept_language.h",
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
/* Do not export this file */
|
/* Do not export this file */
|
||||||
|
|
||||||
#include "../baza.h"
|
#include "../baza.h"
|
||||||
#include "client_request.h"
|
#include "messages.h"
|
||||||
#include <libregexis024vm/libregexis024vm_interface.h>
|
#include <libregexis024vm/libregexis024vm_interface.h>
|
||||||
|
|
||||||
namespace een9 {
|
namespace een9 {
|
||||||
|
@ -17,6 +17,13 @@ namespace een9 {
|
|||||||
bool has_body = false;
|
bool has_body = false;
|
||||||
std::string body;
|
std::string body;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ServerResponse {
|
||||||
|
std::string code;
|
||||||
|
std::string msg;
|
||||||
|
std::vector<std::pair<std::string, std::string>> headers;
|
||||||
|
std::string body;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -5,50 +5,26 @@
|
|||||||
|
|
||||||
|
|
||||||
namespace een9 {
|
namespace een9 {
|
||||||
std::string form_http_server_response_header(const char* code,
|
ServerResponse form_http_server_response_200(const std::string& Content_Type, const std::string& body) {
|
||||||
|
return een9::ServerResponse{"200", "OK",
|
||||||
|
{{"Content-Type", Content_Type}, {"Content-Length", std::to_string(body.size())}}, body};
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerResponse form_http_server_response_404(const std::string& Content_Type, const std::string& body) {
|
||||||
|
return een9::ServerResponse{"404", "ERROR",
|
||||||
|
{{"Content-Type", Content_Type}, {"Content-Length", std::to_string(body.size())}}, body};
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerResponse form_http_server_response_303(const std::string& Location) {
|
||||||
|
return een9::ServerResponse{"303", "Go here", {{"Location", Location}}, ""};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ServerResponse form_http_server_response_303_spec_head(const std::string &Location,
|
||||||
const std::vector<std::pair<std::string, std::string>>& headers) {
|
const std::vector<std::pair<std::string, std::string>>& headers) {
|
||||||
assert(strlen(code) == 3);
|
ServerResponse r{"303", "Go here", {{"Location", Location}}, ""};
|
||||||
std::string result = std::string("HTTP/1.0 ") + code + " " + (code[0] < '4' ? "OK" : "ERROR") + "\r\n";
|
for (auto& hl: headers)
|
||||||
for (auto& p: headers)
|
r.headers.push_back(hl);
|
||||||
result += (p.first + ": " + p.second + "\r\n");
|
return r;
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string form_http_server_response_header_only(const char* code,
|
|
||||||
const std::vector<std::pair<std::string, std::string>>& headers) {
|
|
||||||
return form_http_server_response_header(code, headers) + "\r\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string form_http_server_response_with_body(const char* code,
|
|
||||||
const std::vector<std::pair<std::string, std::string>>& headers,
|
|
||||||
const std::string& body)
|
|
||||||
{
|
|
||||||
std::string result = form_http_server_response_header(code, headers)
|
|
||||||
+ "Content-Length: " + std::to_string(body.size()) + "\r\n\r\n" + body;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Message from server to client */
|
|
||||||
std::string form_http_server_response_200(const std::string& Content_Type, const std::string& body) {
|
|
||||||
return form_http_server_response_with_body("200", {
|
|
||||||
{"Content-Type", Content_Type}
|
|
||||||
}, body);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string form_http_server_response_404(const std::string& Content_Type, const std::string& body) {
|
|
||||||
return form_http_server_response_with_body("404", {
|
|
||||||
{"Content-Type", Content_Type}
|
|
||||||
}, body);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string form_http_server_response_303(const std::string& Location) {
|
|
||||||
return form_http_server_response_header_only("303", {{"Location", Location}});
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string form_http_server_response_303_spec_head(const std::string &Location,
|
|
||||||
const std::vector<std::pair<std::string, std::string>>& headers) {
|
|
||||||
std::vector<std::pair<std::string, std::string>> cp = headers;
|
|
||||||
cp.emplace_back("Location", Location);
|
|
||||||
return form_http_server_response_header_only("303", cp);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,26 +3,16 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "messages.h"
|
||||||
|
|
||||||
namespace een9 {
|
namespace een9 {
|
||||||
std::string form_http_server_response_header(const char* code,
|
ServerResponse form_http_server_response_200(const std::string& Content_Type, const std::string& body);
|
||||||
const std::vector<std::pair<std::string, std::string>>& headers);
|
|
||||||
|
|
||||||
std::string form_http_server_reponse_header_only(const char* code,
|
ServerResponse form_http_server_response_404(const std::string& Content_Type, const std::string& body);
|
||||||
const std::vector<std::pair<std::string, std::string>>& headers);
|
|
||||||
|
|
||||||
std::string form_http_server_response_with_body(const char* code,
|
ServerResponse form_http_server_response_303(const std::string& Location);
|
||||||
const std::vector<std::pair<std::string, std::string>>& headers,
|
|
||||||
const std::string& body);
|
|
||||||
|
|
||||||
std::string form_http_server_response_200(const std::string& Content_Type, const std::string& body);
|
ServerResponse form_http_server_response_303_spec_head(const std::string &Location,
|
||||||
|
|
||||||
std::string form_http_server_response_404(const std::string& Content_Type, const std::string& body);
|
|
||||||
|
|
||||||
std::string form_http_server_response_303(const std::string& Location);
|
|
||||||
|
|
||||||
std::string form_http_server_response_303_spec_head(const std::string &Location,
|
|
||||||
const std::vector<std::pair<std::string, std::string>>& headers);
|
const std::vector<std::pair<std::string, std::string>>& headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,12 +149,22 @@ namespace een9 {
|
|||||||
return pctx.body;
|
return pctx.body;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string server_response_to_str(const ServerResponse& cont) {
|
||||||
|
std::string result = "HTTP/1.0 " + cont.code + " " + cont.msg + "\r\n";
|
||||||
|
for (const std::pair<std::string, std::string>& hl: cont.headers) {
|
||||||
|
result += hl.first + ": " + hl.second + "\r\n";
|
||||||
|
}
|
||||||
|
result += "\r\n" + cont.body;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void process_connection(const SlaveTask& task, WorkersEnv& wte) {
|
void process_connection(const SlaveTask& task, WorkersEnv& wte) {
|
||||||
if (task.conn_info.type == 0) {
|
if (task.conn_info.type == 0) {
|
||||||
printf("%d::Got http reuest\n", wte.id);
|
printf("%d::Got http reuest\n", wte.id);
|
||||||
ClientRequest client_request = process_http_connection_input(task.fd(), task.s_tips, wte);
|
ClientRequest client_request = process_http_connection_input(task.fd(), task.s_tips, wte);
|
||||||
printf("%d::Http request has been read\n", wte.id);
|
printf("%d::Http request has been read\n", wte.id);
|
||||||
std::string server_response = wte.wtec.guest_core(task, client_request, wte.id);
|
ServerResponse server_response_content = wte.wtec.guest_core(task, client_request, wte.id);
|
||||||
|
std::string server_response = server_response_to_str(server_response_content);
|
||||||
process_connection_output(task.fd(), server_response);
|
process_connection_output(task.fd(), server_response);
|
||||||
printf("%d::Http response has been sent\n", wte.id);
|
printf("%d::Http response has been sent\n", wte.id);
|
||||||
} else if (task.conn_info.type == 1) {
|
} else if (task.conn_info.type == 1) {
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include "os_utils.h"
|
#include "os_utils.h"
|
||||||
#include "http_structures/client_request.h"
|
#include "http_structures/messages.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "socket_address.h"
|
#include "socket_address.h"
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ namespace een9 {
|
|||||||
typedef int worker_id_t;
|
typedef int worker_id_t;
|
||||||
|
|
||||||
/* guest_core function must not throw anything that is not derived from std::exception */
|
/* guest_core function must not throw anything that is not derived from std::exception */
|
||||||
typedef std::function<std::string(const SlaveTask&, const ClientRequest&, worker_id_t worker_id)> guest_core_t;
|
typedef std::function<ServerResponse(const SlaveTask&, const ClientRequest&, worker_id_t worker_id)> guest_core_t;
|
||||||
/* same as gurst_core_t, but it used not for http, but for een9 specific "admin-cmd" protocol */
|
/* same as gurst_core_t, but it used not for http, but for een9 specific "admin-cmd" protocol */
|
||||||
typedef std::function<std::string(const SlaveTask&, const std::string&, worker_id_t)> guest_core_admin_control_t;
|
typedef std::function<std::string(const SlaveTask&, const std::string&, worker_id_t)> guest_core_admin_control_t;
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ namespace iu9cawebchat {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string http_R200(const std::string &el_name, WorkerGuestData &wgd,
|
een9::ServerResponse http_R200(const std::string &el_name, WorkerGuestData &wgd,
|
||||||
const std::vector<const json::JSON *> &args) {
|
const std::vector<const json::JSON *> &args) {
|
||||||
std::string page = wgd.templater->render(el_name, args);
|
std::string page = wgd.templater->render(el_name, args);
|
||||||
return een9::form_http_server_response_200("text/html", page);
|
return een9::form_http_server_response_200("text/html", page);
|
||||||
@ -40,52 +40,52 @@ namespace iu9cawebchat {
|
|||||||
return jmessages;
|
return jmessages;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string page_E404(WorkerGuestData &wgd) {
|
een9::ServerResponse page_E404(WorkerGuestData &wgd) {
|
||||||
return een9::form_http_server_response_404("text/html",
|
return een9::form_http_server_response_404("text/html",
|
||||||
wgd.templater->render("err-404", {}));
|
wgd.templater->render("err-404", {}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ========================= API =========================*/
|
/* ========================= API =========================*/
|
||||||
std::string when_internalapi(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid,
|
een9::ServerResponse when_internalapi(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid,
|
||||||
const std::function<json::JSON(SqliteConnection&, int64_t, const json::JSON&)>& F) {
|
const std::function<json::JSON(SqliteConnection&, int64_t, const json::JSON&)>& F) {
|
||||||
const json::JSON& Sent = json::parse_str_flawless(req.body);
|
const json::JSON& Sent = json::parse_str_flawless(req.body);
|
||||||
std::string result = json::generate_str(F(*wgd.db, uid, Sent), json::print_pretty);
|
std::string result = json::generate_str(F(*wgd.db, uid, Sent), json::print_pretty);
|
||||||
return een9::form_http_server_response_200("text/json", result);
|
return een9::form_http_server_response_200("text/json", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string when_internalapi_chatpollevents(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid) {
|
een9::ServerResponse when_internalapi_chatpollevents(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid) {
|
||||||
return when_internalapi(wgd, req, uid, internalapi_chatPollEvents);
|
return when_internalapi(wgd, req, uid, internalapi_chatPollEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string when_internalapi_chatlistpollevents(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid) {
|
een9::ServerResponse when_internalapi_chatlistpollevents(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid) {
|
||||||
return when_internalapi(wgd, req, uid, internalapi_chatListPollEvents);
|
return when_internalapi(wgd, req, uid, internalapi_chatListPollEvents);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string when_internalapi_getmessageneighbours(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid) {
|
een9::ServerResponse when_internalapi_getmessageneighbours(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid) {
|
||||||
return when_internalapi(wgd, req, uid, internalapi_getMessageNeighbours);
|
return when_internalapi(wgd, req, uid, internalapi_getMessageNeighbours);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string when_internalapi_sendmessage(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid) {
|
een9::ServerResponse when_internalapi_sendmessage(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid) {
|
||||||
return when_internalapi(wgd, req, uid, internalapi_sendMessage);
|
return when_internalapi(wgd, req, uid, internalapi_sendMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string when_internalapi_deletemessage(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid) {
|
een9::ServerResponse when_internalapi_deletemessage(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid) {
|
||||||
return when_internalapi(wgd, req, uid, internalapi_deleteMessage);
|
return when_internalapi(wgd, req, uid, internalapi_deleteMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string when_internalapi_addmembertochat(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid) {
|
een9::ServerResponse when_internalapi_addmembertochat(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid) {
|
||||||
return when_internalapi(wgd, req, uid, internalapi_addMemberToChat);
|
return when_internalapi(wgd, req, uid, internalapi_addMemberToChat);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string when_internalapi_removememberfromchat(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid) {
|
een9::ServerResponse when_internalapi_removememberfromchat(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid) {
|
||||||
return when_internalapi(wgd, req, uid, internalapi_removeMemberFromChat);
|
return when_internalapi(wgd, req, uid, internalapi_removeMemberFromChat);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string when_internalapi_createchat(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid) {
|
een9::ServerResponse when_internalapi_createchat(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid) {
|
||||||
return when_internalapi(wgd, req, uid, internalapi_createChat);
|
return when_internalapi(wgd, req, uid, internalapi_createChat);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string when_internalapi_leavechat(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid) {
|
een9::ServerResponse when_internalapi_leavechat(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid) {
|
||||||
return when_internalapi(wgd, req, uid, internalapi_leaveChat);
|
return when_internalapi(wgd, req, uid, internalapi_leaveChat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include "server_data_interact.h"
|
#include "server_data_interact.h"
|
||||||
|
|
||||||
#include "../sqlite3_wrapper.h"
|
#include "../sqlite3_wrapper.h"
|
||||||
#include <engine_engine_number_9/http_structures/client_request.h>
|
#include <engine_engine_number_9/http_structures/messages.h>
|
||||||
#include <engine_engine_number_9/http_structures/response_gen.h>
|
#include <engine_engine_number_9/http_structures/response_gen.h>
|
||||||
#include "../login_cookie.h"
|
#include "../login_cookie.h"
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ namespace iu9cawebchat {
|
|||||||
int64_t& ret_logged_in_user
|
int64_t& ret_logged_in_user
|
||||||
);
|
);
|
||||||
|
|
||||||
std::string http_R200(const std::string& el_name, WorkerGuestData& wgd,
|
een9::ServerResponse http_R200(const std::string& el_name, WorkerGuestData& wgd,
|
||||||
const std::vector<const json::JSON*>& args);
|
const std::vector<const json::JSON*>& args);
|
||||||
|
|
||||||
struct HtmlMsgBox {
|
struct HtmlMsgBox {
|
||||||
@ -39,43 +39,43 @@ namespace iu9cawebchat {
|
|||||||
|
|
||||||
json::JSON jsonify_html_message_list(const std::vector<HtmlMsgBox>& messages);
|
json::JSON jsonify_html_message_list(const std::vector<HtmlMsgBox>& messages);
|
||||||
|
|
||||||
std::string page_E404(WorkerGuestData& wgd);
|
een9::ServerResponse page_E404(WorkerGuestData& wgd);
|
||||||
|
|
||||||
/* ========================== PAGES ================================== */
|
/* ========================== PAGES ================================== */
|
||||||
|
|
||||||
std::string when_page_list_rooms(WorkerGuestData& wgd, const json::JSON& config_presentation,
|
een9::ServerResponse when_page_list_rooms(WorkerGuestData& wgd, const json::JSON& config_presentation,
|
||||||
const een9::ClientRequest& req, const json::JSON& userinfo);
|
const een9::ClientRequest& req, const json::JSON& userinfo);
|
||||||
|
|
||||||
std::string when_page_login(WorkerGuestData& wgd, const json::JSON& config_presentation,
|
een9::ServerResponse when_page_login(WorkerGuestData& wgd, const json::JSON& config_presentation,
|
||||||
const een9::ClientRequest& req, const std::vector<LoginCookie>& login_cookies, const json::JSON& userinfo);
|
const een9::ClientRequest& req, const std::vector<LoginCookie>& login_cookies, const json::JSON& userinfo);
|
||||||
|
|
||||||
std::string when_page_chat(WorkerGuestData& wgd, const json::JSON& config_presentation,
|
een9::ServerResponse when_page_chat(WorkerGuestData& wgd, const json::JSON& config_presentation,
|
||||||
const een9::ClientRequest& req, const json::JSON& userinfo);
|
const een9::ClientRequest& req, const json::JSON& userinfo);
|
||||||
|
|
||||||
std::string when_page_user(WorkerGuestData& wgd, const json::JSON& config_presentation,
|
een9::ServerResponse when_page_user(WorkerGuestData& wgd, const json::JSON& config_presentation,
|
||||||
const een9::ClientRequest& req, const std::vector<LoginCookie>& login_cookies, const json::JSON& userinfo);
|
const een9::ClientRequest& req, const std::vector<LoginCookie>& login_cookies, const json::JSON& userinfo);
|
||||||
|
|
||||||
std::string when_page_register(WorkerGuestData& wgd, const json::JSON& config_presentation,
|
een9::ServerResponse when_page_register(WorkerGuestData& wgd, const json::JSON& config_presentation,
|
||||||
const een9::ClientRequest& req, const json::JSON& userinfo);
|
const een9::ClientRequest& req, const json::JSON& userinfo);
|
||||||
|
|
||||||
/* ======================== API ============================== */
|
/* ======================== API ============================== */
|
||||||
std::string when_internalapi_chatpollevents(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid);
|
een9::ServerResponse when_internalapi_chatpollevents(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid);
|
||||||
|
|
||||||
std::string when_internalapi_chatlistpollevents(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid);
|
een9::ServerResponse when_internalapi_chatlistpollevents(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid);
|
||||||
|
|
||||||
std::string when_internalapi_getmessageneighbours(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid);
|
een9::ServerResponse when_internalapi_getmessageneighbours(WorkerGuestData& wgd, const een9::ClientRequest& req, int64_t uid);
|
||||||
|
|
||||||
std::string when_internalapi_sendmessage(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid);
|
een9::ServerResponse when_internalapi_sendmessage(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid);
|
||||||
|
|
||||||
std::string when_internalapi_deletemessage(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid);
|
een9::ServerResponse when_internalapi_deletemessage(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid);
|
||||||
|
|
||||||
std::string when_internalapi_addmembertochat(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid);
|
een9::ServerResponse when_internalapi_addmembertochat(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid);
|
||||||
|
|
||||||
std::string when_internalapi_removememberfromchat(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid);
|
een9::ServerResponse when_internalapi_removememberfromchat(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid);
|
||||||
|
|
||||||
std::string when_internalapi_createchat(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid);
|
een9::ServerResponse when_internalapi_createchat(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid);
|
||||||
|
|
||||||
std::string when_internalapi_leavechat(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid);
|
een9::ServerResponse when_internalapi_leavechat(WorkerGuestData &wgd, const een9::ClientRequest &req, int64_t uid);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include "../str_fields.h"
|
#include "../str_fields.h"
|
||||||
|
|
||||||
namespace iu9cawebchat {
|
namespace iu9cawebchat {
|
||||||
std::string when_page_chat(WorkerGuestData& wgd, const json::JSON& config_presentation,
|
een9::ServerResponse when_page_chat(WorkerGuestData& wgd, const json::JSON& config_presentation,
|
||||||
const een9::ClientRequest& req, const json::JSON& userinfo) {
|
const een9::ClientRequest& req, const json::JSON& userinfo) {
|
||||||
|
|
||||||
std::vector<std::string> path_segs = {};
|
std::vector<std::string> path_segs = {};
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include "client_server_interact.h"
|
#include "client_server_interact.h"
|
||||||
|
|
||||||
namespace iu9cawebchat {
|
namespace iu9cawebchat {
|
||||||
std::string when_page_list_rooms(WorkerGuestData& wgd, const json::JSON& config_presentation,
|
een9::ServerResponse when_page_list_rooms(WorkerGuestData& wgd, const json::JSON& config_presentation,
|
||||||
const een9::ClientRequest& req, const json::JSON& userinfo) {
|
const een9::ClientRequest& req, const json::JSON& userinfo) {
|
||||||
if (userinfo.isNull()) {
|
if (userinfo.isNull()) {
|
||||||
return een9::form_http_server_response_303("/login");
|
return een9::form_http_server_response_303("/login");
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
#include "../str_fields.h"
|
#include "../str_fields.h"
|
||||||
|
|
||||||
namespace iu9cawebchat {
|
namespace iu9cawebchat {
|
||||||
std::string when_page_login(WorkerGuestData& wgd, const json::JSON& config_presentation,
|
een9::ServerResponse when_page_login(WorkerGuestData& wgd, const json::JSON& config_presentation,
|
||||||
const een9::ClientRequest& req, const std::vector<LoginCookie>& login_cookies, const json::JSON& userinfo) {
|
const een9::ClientRequest& req, const std::vector<LoginCookie>& login_cookies, const json::JSON& userinfo) {
|
||||||
if (req.method == "POST") {
|
if (req.method == "POST") {
|
||||||
std::vector<std::pair<std::string, std::string>> query = een9::split_html_query(req.body);
|
std::vector<std::pair<std::string, std::string>> query = een9::split_html_query(req.body);
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
#include "../str_fields.h"
|
#include "../str_fields.h"
|
||||||
|
|
||||||
namespace iu9cawebchat {
|
namespace iu9cawebchat {
|
||||||
std::string when_page_register(WorkerGuestData& wgd, const json::JSON& config_presentation,
|
een9::ServerResponse when_page_register(WorkerGuestData& wgd, const json::JSON& config_presentation,
|
||||||
const een9::ClientRequest& req, const json::JSON& userinfo) {
|
const een9::ClientRequest& req, const json::JSON& userinfo) {
|
||||||
|
|
||||||
const json::JSON& reg_pres = config_presentation["register"];
|
const json::JSON& reg_pres = config_presentation["register"];
|
||||||
|
@ -7,7 +7,8 @@
|
|||||||
|
|
||||||
namespace iu9cawebchat {
|
namespace iu9cawebchat {
|
||||||
std::string get_user_bio(SqliteConnection& conn, int64_t userId) {
|
std::string get_user_bio(SqliteConnection& conn, int64_t userId) {
|
||||||
een9_ASSERT(userId >= 0, "Are you crazy?");
|
if (userId < 0)
|
||||||
|
een9_THROW("Are you crazy?");
|
||||||
SqliteStatement sql_req(conn, "SELECT `bio` FROM `user` WHERE `id` = ?1", {{1, userId}}, {});
|
SqliteStatement sql_req(conn, "SELECT `bio` FROM `user` WHERE `id` = ?1", {{1, userId}}, {});
|
||||||
fsql_text8_or_null bio_col;
|
fsql_text8_or_null bio_col;
|
||||||
int status = sqlite_stmt_step(sql_req, {}, {{0, &bio_col}});
|
int status = sqlite_stmt_step(sql_req, {}, {{0, &bio_col}});
|
||||||
@ -37,7 +38,7 @@ namespace iu9cawebchat {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string when_page_user(WorkerGuestData& wgd, const json::JSON& config_presentation,
|
een9::ServerResponse when_page_user(WorkerGuestData& wgd, const json::JSON& config_presentation,
|
||||||
const een9::ClientRequest& req, const std::vector<LoginCookie>& login_cookies, const json::JSON& userinfo) {
|
const een9::ClientRequest& req, const std::vector<LoginCookie>& login_cookies, const json::JSON& userinfo) {
|
||||||
if (userinfo.isNull())
|
if (userinfo.isNull())
|
||||||
return een9::form_http_server_response_303("/");
|
return een9::form_http_server_response_303("/");
|
||||||
|
@ -78,7 +78,7 @@ namespace iu9cawebchat {
|
|||||||
|
|
||||||
een9::MainloopParameters params;
|
een9::MainloopParameters params;
|
||||||
params.guest_core = [&samI, &worker_guest_data]
|
params.guest_core = [&samI, &worker_guest_data]
|
||||||
(const een9::SlaveTask& task, const een9::ClientRequest& req, een9::worker_id_t worker_id) -> std::string {
|
(const een9::SlaveTask& task, const een9::ClientRequest& req, een9::worker_id_t worker_id) -> een9::ServerResponse {
|
||||||
een9_ASSERT_pl(0 <= worker_id && worker_id < worker_guest_data.size());
|
een9_ASSERT_pl(0 <= worker_id && worker_id < worker_guest_data.size());
|
||||||
WorkerGuestData& wgd = worker_guest_data[worker_id];
|
WorkerGuestData& wgd = worker_guest_data[worker_id];
|
||||||
een9::StaticAsset sa;
|
een9::StaticAsset sa;
|
||||||
|
@ -76,7 +76,7 @@ namespace iu9cawebchat {
|
|||||||
|
|
||||||
int ret = sqlite3_prepare_v2(connection.hand, req_statement.c_str(), -1, &stmt_obj, NULL);
|
int ret = sqlite3_prepare_v2(connection.hand, req_statement.c_str(), -1, &stmt_obj, NULL);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
int err_pos = -1;
|
int err_pos = sqlite3_error_offset(connection.hand);
|
||||||
een9_THROW("Compilation of request\n" + req_statement + "\nfailed" +
|
een9_THROW("Compilation of request\n" + req_statement + "\nfailed" +
|
||||||
((err_pos >= 0) ? " with offset " + std::to_string(err_pos) : ""));
|
((err_pos >= 0) ? " with offset " + std::to_string(err_pos) : ""));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user