Update README (#225)

* Update README

* Update CMakeLists.txt
This commit is contained in:
An Tao 2019-08-24 22:44:37 +08:00 committed by GitHub
parent 4e274b1a2e
commit ba49a0e0e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 98 additions and 88 deletions

View File

@ -159,12 +159,12 @@ if(BUILD_ORM)
CMAKE_FLAGS "-DINCLUDE_DIRECTORIES=${PostgreSQL_INCLUDE_DIR}")
endif()
if(libpq_supports_batch)
message(STATUS "The libpq supports fatch mode")
OPTION(LIBPQ_SUPPORTS_BATCH_MODE "ibpq fatch mode" ON)
message(STATUS "The libpq supports batch mode")
option(LIBPQ_SUPPORTS_BATCH_MODE "libpq batch mode" ON)
set(DROGON_SOURCES ${DROGON_SOURCES}
orm_lib/src/postgresql_impl/PgBatchConnection.cc)
else()
OPTION(LIBPQ_SUPPORTS_BATCH_MODE "ibpq fatch mode" OFF)
option(LIBPQ_SUPPORTS_BATCH_MODE "libpq batch mode" OFF)
set(DROGON_SOURCES ${DROGON_SOURCES}
orm_lib/src/postgresql_impl/PgConnection.cc)
endif()

View File

@ -45,12 +45,12 @@ Below is the main program of a typical drogon application:
using namespace drogon;
int main()
{
app().setLogPath("./");
app().setLogLevel(trantor::Logger::WARN);
app().addListener("0.0.0.0", 80);
app().setThreadNum(16);
app().enableRunAsDaemon();
app().run();
app().setLogPath("./")
.setLogLevel(trantor::Logger::WARN)
.addListener("0.0.0.0", 80)
.setThreadNum(16)
.enableRunAsDaemon()
.run();
}
```
@ -61,8 +61,7 @@ It can be further simplified by using configuration file as follows:
using namespace drogon;
int main()
{
app().loadConfigFile("./config.json");
app().run();
app().loadConfigFile("./config.json").run();
}
```

View File

@ -57,6 +57,9 @@ std::string base64Encode(const unsigned char *bytes_to_encode,
/// Decode the base64 format string.
std::string base64Decode(std::string const &encoded_string);
/// Check if the string need decoding
bool needUrlDecoding(const char *begin, const char *end);
/// Decode from or encode to the URL format string
std::string urlDecode(const char *begin, const char *end);
inline std::string urlDecode(const std::string &szToDecode)

View File

@ -54,7 +54,7 @@ class HttpRequestImpl : public HttpRequest
_headers.clear();
_cookies.clear();
_flagForParsingParameters = false;
//_path.clear();
_path.clear();
_matchedPathPattern = "";
_query.clear();
_parameters.clear();
@ -98,7 +98,14 @@ class HttpRequestImpl : public HttpRequest
void setPath(const char *start, const char *end)
{
_path = utils::urlDecode(start, end);
if(utils::needUrlDecoding(start,end))
{
_path = utils::urlDecode(start, end);
}
else
{
_path.append(start, end);
}
}
virtual void setPath(const std::string &path) override

View File

@ -455,88 +455,84 @@ std::string urlEncode(const std::string &src)
return result;
}
bool needUrlDecoding(const char *begin, const char *end)
{
return std::find_if(begin, end, [](const char c) {
return c == '+' || c == '%';
}) != end;
}
std::string urlDecode(const char *begin, const char *end)
{
if (std::find_if(begin, end, [](const char c) {
return c == '+' || c == '%';
}) != end)
std::string result;
size_t len = end - begin;
result.reserve(len * 2);
int hex = 0;
for (size_t i = 0; i < len; ++i)
{
std::string result;
size_t len = end - begin;
result.reserve(len);
int hex = 0;
for (size_t i = 0; i < len; ++i)
switch (begin[i])
{
switch (begin[i])
{
case '+':
result += ' ';
break;
case '%':
if ((i + 2) < len && isxdigit(begin[i + 1]) &&
isxdigit(begin[i + 2]))
case '+':
result += ' ';
break;
case '%':
if ((i + 2) < len && isxdigit(begin[i + 1]) &&
isxdigit(begin[i + 2]))
{
uint x1 = begin[i + 1];
if (x1 >= '0' && x1 <= '9')
{
uint x1 = begin[i + 1];
if (x1 >= '0' && x1 <= '9')
{
x1 -= '0';
}
else if (x1 >= 'a' && x1 <= 'f')
{
x1 = x1 - 'a' + 10;
}
else if (x1 >= 'A' && x1 <= 'F')
{
x1 = x1 - 'A' + 10;
}
uint x2 = begin[i + 2];
if (x2 >= '0' && x2 <= '9')
{
x2 -= '0';
}
else if (x2 >= 'a' && x2 <= 'f')
{
x2 = x2 - 'a' + 10;
}
else if (x2 >= 'A' && x2 <= 'F')
{
x2 = x2 - 'A' + 10;
}
hex = x1 * 16 + x2;
if (!((hex >= 48 && hex <= 57) || // 0-9
(hex >= 97 && hex <= 122) || // a-z
(hex >= 65 && hex <= 90) || // A-Z
//[$-_.+!*'(),] [$&+,/:;?@]
hex == 0x21 || hex == 0x24 || hex == 0x26 ||
hex == 0x27 || hex == 0x28 || hex == 0x29 ||
hex == 0x2a || hex == 0x2b || hex == 0x2c ||
hex == 0x2d || hex == 0x2e || hex == 0x2f ||
hex == 0x3A || hex == 0x3B || hex == 0x3f ||
hex == 0x40 || hex == 0x5f))
{
result += char(hex);
i += 2;
}
else
result += '%';
x1 -= '0';
}
else if (x1 >= 'a' && x1 <= 'f')
{
x1 = x1 - 'a' + 10;
}
else if (x1 >= 'A' && x1 <= 'F')
{
x1 = x1 - 'A' + 10;
}
uint x2 = begin[i + 2];
if (x2 >= '0' && x2 <= '9')
{
x2 -= '0';
}
else if (x2 >= 'a' && x2 <= 'f')
{
x2 = x2 - 'a' + 10;
}
else if (x2 >= 'A' && x2 <= 'F')
{
x2 = x2 - 'A' + 10;
}
hex = x1 * 16 + x2;
if (!((hex >= 48 && hex <= 57) || // 0-9
(hex >= 97 && hex <= 122) || // a-z
(hex >= 65 && hex <= 90) || // A-Z
//[$-_.+!*'(),] [$&+,/:;?@]
hex == 0x21 || hex == 0x24 || hex == 0x26 ||
hex == 0x27 || hex == 0x28 || hex == 0x29 ||
hex == 0x2a || hex == 0x2b || hex == 0x2c ||
hex == 0x2d || hex == 0x2e || hex == 0x2f ||
hex == 0x3A || hex == 0x3B || hex == 0x3f ||
hex == 0x40 || hex == 0x5f))
{
result += char(hex);
i += 2;
}
else
{
result += '%';
}
break;
default:
result += begin[i];
break;
}
}
else
{
result += '%';
}
break;
default:
result += begin[i];
break;
}
return result;
}
else
{
return std::string(begin, end);
}
return result;
}
/* Compress gzip data */

View File

@ -27,6 +27,7 @@ namespace drogon
{
namespace orm
{
static const unsigned int maxBatchCount = 256;
Result makeResult(
const std::shared_ptr<PGresult> &r = std::shared_ptr<PGresult>(nullptr),
const std::string &query = "")
@ -286,16 +287,17 @@ void PgConnection::sendBatchedSql()
{
statName = cmd->_preparingStatement;
}
if (_batchSqlCommands.size() == 1)
if (_batchSqlCommands.size() == 1 || cmd->_sql.length() > 1024 ||
_batchCount > maxBatchCount)
{
_sendBatchEnd = true;
_batchCount = 0;
}
else
{
auto sql = cmd->_sql;
std::transform(sql.begin(), sql.end(), sql.begin(), tolower);
if (sql.length() > 1024 ||
sql.find("update") != std::string::npos ||
if (sql.find("update") != std::string::npos ||
sql.find("insert") != std::string::npos ||
sql.find("delete") != std::string::npos ||
sql.find("drop") != std::string::npos ||
@ -303,8 +305,10 @@ void PgConnection::sendBatchedSql()
sql.find("lock") != std::string::npos)
{
_sendBatchEnd = true;
_batchCount = 0;
}
}
++_batchCount;
if (PQsendQueryPrepared(_connPtr.get(),
statName.c_str(),
cmd->_paraNum,

View File

@ -117,6 +117,7 @@ class PgConnection : public DbConnection,
void sendBatchedSql();
int sendBatchEnd();
bool _sendBatchEnd = false;
unsigned int _batchCount = 0;
#endif
};