Printing bad requests to log/req
This commit is contained in:
parent
06d5a33495
commit
38d3a2ea78
1
.gitignore
vendored
1
.gitignore
vendored
@ -13,3 +13,4 @@ compile_commands.json
|
||||
local.sh
|
||||
|
||||
iu9-ca-web-chat.db
|
||||
log
|
||||
|
@ -69,9 +69,7 @@ regexis024_build_system.sh
|
||||
|
||||
Зачем писать комментарии в коде, если можно их вынести в отдельные пдф-ки?
|
||||
|
||||
- [API сервиса](
|
||||
- [Документация для разработчиков](
|
||||
https://gitlab.yyyi.ru/collarbone-annihilation/iu9-ca-chat-api)
|
||||
- [Доки New York Transit Line](
|
||||
https://gitlab.yyyi.ru/collarbone-annihilation/new_york_transit_line_documentation_rus)
|
||||
|
||||
О том как работает всё остальное можно только догадываться.
|
||||
|
@ -3,6 +3,13 @@
|
||||
#include <libregexis024tools/delayed_matching.h>
|
||||
#include <algorithm>
|
||||
#include <assert.h>
|
||||
// Used for debug
|
||||
|
||||
#include "unistd.h"
|
||||
#include <sys/stat.h>
|
||||
#include "sys/dir.h"
|
||||
#include "../os_utils.h"
|
||||
|
||||
|
||||
namespace een9 {
|
||||
ClientRequestParser_CommonPrograms::ClientRequestParser_CommonPrograms() {
|
||||
@ -109,6 +116,10 @@ namespace een9 {
|
||||
}
|
||||
/* We either finish now or we finish later */
|
||||
} else if (!vm.haveSurvivors()) {
|
||||
#ifdef DEBUG_ALLOW_LOUD
|
||||
mkdir("log", 0750);
|
||||
writeFile("log/req", header);
|
||||
#endif
|
||||
status = -1;
|
||||
THROW("bad request");
|
||||
}
|
||||
|
@ -67,6 +67,28 @@ namespace een9 {
|
||||
readFromFileDescriptor(fdw(), result, "file \"" + path + "\"");
|
||||
}
|
||||
|
||||
|
||||
/* write(fd, text); close(fd); */
|
||||
void writeToFileDescriptor(int fd, const std::string& text, const std::string& description = "") {
|
||||
size_t n = text.size();
|
||||
size_t i = 0;
|
||||
while (i < n) {
|
||||
size_t block = std::min(2048lu, n - i);
|
||||
int ret = write(fd, &text[i], block);
|
||||
ASSERT_on_iret(ret, "Writing to" + description);
|
||||
i += ret;
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
|
||||
/* Truncational */
|
||||
void writeFile(const std::string& path, const std::string& text) {
|
||||
int fd = open(path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, 0755);
|
||||
ASSERT_on_iret(fd, "Opening \"" + path + "\"");
|
||||
UniqueFdWrapper fdw(fd);
|
||||
writeToFileDescriptor(fdw(), text, "file \"" + path + "\n");
|
||||
}
|
||||
|
||||
void configure_socket_rcvsndtimeo(int fd, timeval tv) {
|
||||
int ret;
|
||||
ret = setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(timeval));
|
||||
|
@ -30,6 +30,8 @@ namespace een9 {
|
||||
|
||||
void readFile(const std::string& path, std::string& result);
|
||||
|
||||
void writeFile(const std::string& path, const std::string& text);
|
||||
|
||||
void configure_socket_rcvsndtimeo(int fd, timeval tv);
|
||||
}
|
||||
|
||||
|
@ -4,11 +4,14 @@
|
||||
#include <sqlite3.h>
|
||||
#include <engine_engine_number_9/os_utils.h>
|
||||
#include <find_db.h>
|
||||
#include <unistd.h>
|
||||
#include <assert.h>
|
||||
|
||||
void sqlite_single_statement(sqlite3* db_hand, const std::string& req_statement) {
|
||||
sqlite3_stmt* stmt_obj = NULL;
|
||||
int ret = sqlite3_prepare16_v2(db_hand, req_statement.c_str(), -1, &stmt_obj, NULL);
|
||||
int ret = sqlite3_prepare_v2(db_hand, req_statement.c_str(), -1, &stmt_obj, NULL);
|
||||
een9_ASSERT(ret == 0, "Can't compile request expression");
|
||||
assert(sqlite3_errcode(db_hand) == SQLITE_OK);
|
||||
struct Guard1{sqlite3_stmt*& r; ~Guard1(){if (sqlite3_finalize(r) != 0) {abort();}}} guard1{stmt_obj};
|
||||
while (true) {
|
||||
ret = sqlite3_step(stmt_obj);
|
||||
@ -34,6 +37,29 @@ void sqlite_single_statement(sqlite3* db_hand, const std::string& req_statement)
|
||||
ccase(NULL)
|
||||
case SQLITE3_TEXT:
|
||||
printf(" TEXT |"); break;
|
||||
default:
|
||||
een9_THROW("AAAAAA");
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
printf("Values: | ");
|
||||
for (int i = 0; i < cc; i++) {
|
||||
if (types[i] == SQLITE_INTEGER) {
|
||||
printf("%ld | ", sqlite3_column_int64(stmt_obj, i));
|
||||
} else if (types[i] == SQLITE_FLOAT) {
|
||||
printf("%lf | ", sqlite3_column_double(stmt_obj, i));
|
||||
} else if (types[i] == SQLITE_BLOB) {
|
||||
const void* blob = sqlite3_column_blob(stmt_obj, i);
|
||||
een9_ASSERT(sqlite3_errcode(db_hand) == SQLITE_OK, "oom in sqlite3_column_blob");
|
||||
size_t sz = sqlite3_column_bytes(stmt_obj, i);
|
||||
printf("Blob of size %s | ", sz);
|
||||
} else if (types[i] == SQLITE_NULL) {
|
||||
printf("NULL | ");
|
||||
} else {
|
||||
const unsigned char* text = sqlite3_column_text(stmt_obj, i);
|
||||
een9_ASSERT(sqlite3_errcode(db_hand) != SQLITE_NOMEM, "oom in sqlite3_column_text");
|
||||
printf("%s | ", (const char*)text);
|
||||
// todo: THIS F. B.S. IS NOT SAFE
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
@ -48,12 +74,22 @@ void initialize_website(const json::JSON& config, const std::string& root_pw) {
|
||||
int ret;
|
||||
ret = find_db_sqlite_file_path(config, db_path);
|
||||
een9_ASSERT(ret == 0, "Invalid settings[\"database\"] field");
|
||||
if (een9::isRegularFile(db_path)) {
|
||||
// todo: plaese, don't do this
|
||||
ret = unlink(db_path.c_str());
|
||||
een9_ASSERT_pl(ret == 0);
|
||||
}
|
||||
een9_ASSERT(!een9::isRegularFile(db_path), "Database file exists prior to initialization. "
|
||||
"Can't preceed withut harming existing data");
|
||||
// sqlite3* db_hand = NULL;
|
||||
// ret = sqlite3_open(db_path.c_str(), &db_hand);
|
||||
// een9_ASSERT(ret == 0, "Can't open database");
|
||||
// struct Guard1{sqlite3*& dhp; ~Guard1(){if (sqlite3_close(dhp) != 0) {abort();}}} guard1{db_hand};
|
||||
// sqlite_single_statement(db_hand, "CREATE TABLE tb(a INT, b INT);");
|
||||
sqlite3* db_hand = NULL;
|
||||
ret = sqlite3_open(db_path.c_str(), &db_hand);
|
||||
een9_ASSERT(ret == 0, "Can't open database");
|
||||
assert(sqlite3_errcode(db_hand) == SQLITE_OK);
|
||||
struct Guard1{sqlite3*& dhp; ~Guard1(){if (sqlite3_close(dhp) != 0) {abort();}}} guard1{db_hand};
|
||||
sqlite_single_statement(db_hand, "CREATE TABLE tb(a INT, b INT)");
|
||||
sqlite_single_statement(db_hand, "INSERT INTO tb(a) VALUES (111)");
|
||||
sqlite_single_statement(db_hand, "INSERT INTO tb(b) VALUES ('yaeyahiyagdohzghz5echp')");
|
||||
sqlite_single_statement(db_hand, "INSERT INTO tb(a, b) VALUES (1123123, 'string')");
|
||||
sqlite_single_statement(db_hand, "SELECT * FROM tb");
|
||||
// todo: actually write something
|
||||
}
|
Loading…
Reference in New Issue
Block a user