Skip to content

Commit

Permalink
*: Use HTTP_Field_Name
Browse files Browse the repository at this point in the history
  • Loading branch information
lhmouse committed Jun 10, 2024
1 parent 1ef91f1 commit 229d8ec
Show file tree
Hide file tree
Showing 19 changed files with 125 additions and 214 deletions.
27 changes: 11 additions & 16 deletions poseidon/easy/easy_hws_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,22 +155,17 @@ struct Final_Session final : WS_Server_Session
return http_payload_normal;
}

if((req.method == http_GET) || (req.method == http_HEAD)) {
bool has_upgrade = false;
for(const auto& r : req.headers)
has_upgrade |= ascii_ci_equal(r.first, "Upgrade");

if(!has_upgrade) {
// Handle an HTTP request.
Session_Table::Event_Queue::Event event;
event.type = (req.method == http_GET) ? easy_hws_get : easy_hws_head;
event.data.putn(req.uri_host.data(), req.uri_host.size());
event.data.putn(req.uri_path.data(), req.uri_path.size());
event.data.putc('?');
event.data.putn(req.uri_query.data(), req.uri_query.size());
this->do_push_event_common(move(event));
return http_payload_normal;
}
if(((req.method == http_GET) || (req.method == http_HEAD))
&& none_of(req.headers, [&](const auto& r) { return r.first == "Upgrade"; })) {
// Handle an HTTP request.
Session_Table::Event_Queue::Event event;
event.type = (req.method == http_GET) ? easy_hws_get : easy_hws_head;
event.data.putn(req.uri_host.data(), req.uri_host.size());
event.data.putn(req.uri_path.data(), req.uri_path.size());
event.data.putc('?');
event.data.putn(req.uri_query.data(), req.uri_query.size());
this->do_push_event_common(move(event));
return http_payload_normal;
}

// default
Expand Down
27 changes: 11 additions & 16 deletions poseidon/easy/easy_hwss_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,22 +155,17 @@ struct Final_Session final : WSS_Server_Session
return http_payload_normal;
}

if((req.method == http_GET) || (req.method == http_HEAD)) {
bool has_upgrade = false;
for(const auto& r : req.headers)
has_upgrade |= ascii_ci_equal(r.first, "Upgrade");

if(!has_upgrade) {
// Handle an HTTP request.
Session_Table::Event_Queue::Event event;
event.type = (req.method == http_GET) ? easy_hws_get : easy_hws_head;
event.data.putn(req.uri_host.data(), req.uri_host.size());
event.data.putn(req.uri_path.data(), req.uri_path.size());
event.data.putc('?');
event.data.putn(req.uri_query.data(), req.uri_query.size());
this->do_push_event_common(move(event));
return http_payload_normal;
}
if(((req.method == http_GET) || (req.method == http_HEAD))
&& none_of(req.headers, [&](const auto& r) { return r.first == "Upgrade"; })) {
// Handle an HTTP request.
Session_Table::Event_Queue::Event event;
event.type = (req.method == http_GET) ? easy_hws_get : easy_hws_head;
event.data.putn(req.uri_host.data(), req.uri_host.size());
event.data.putn(req.uri_path.data(), req.uri_path.size());
event.data.putc('?');
event.data.putn(req.uri_query.data(), req.uri_query.size());
this->do_push_event_common(move(event));
return http_payload_normal;
}

// default
Expand Down
70 changes: 35 additions & 35 deletions poseidon/fiber/mysql_check_table_future.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ do_append_column_definition(tinyfmt_str& sql, const MySQL_Table_Structure::Colum
if(column.nullable == false)
sql << " NOT NULL";

if(!column.default_value.is_null())
if(column.default_value.is_null() == false)
sql << " DEFAULT " << column.default_value;
}

void
do_append_index_definition(tinyfmt_str& sql, const MySQL_Table_Structure::Index& index)
{
if(ascii_ci_equal(index.name, "PRIMARY"))
if(index.name == "PRIMARY")
sql << "PRIMARY KEY";
else
switch(index.type)
Expand Down Expand Up @@ -214,15 +214,15 @@ do_on_abstract_future_execute()
::std::map<cow_string, exColumn> excolumns;

for(uint32_t t = 0; t != fields.size(); ++t)
if(ascii_ci_equal(fields[t], "field"))
if(fields[t]== "Field")
idx_name = t;
else if(ascii_ci_equal(fields[t], "type"))
else if(fields[t] == "Type")
idx_type = t;
else if(ascii_ci_equal(fields[t], "null"))
else if(fields[t] == "Null")
idx_nullable = t;
else if(ascii_ci_equal(fields[t], "default"))
else if(fields[t] == "Default")
idx_default_value = t;
else if(ascii_ci_equal(fields[t], "extra"))
else if(fields[t] == "Extra")
idx_extra = t;

while(this->m_conn->fetch_row(row)) {
Expand All @@ -233,7 +233,7 @@ do_on_abstract_future_execute()
// Save this column.
exColumn& r = excolumns[name];
r.type = row.at(idx_type).as_blob();
r.nullable = ascii_ci_equal(row.at(idx_nullable).as_blob(), "yes");
r.nullable = row.at(idx_nullable).as_blob() == "YES";
r.default_value = move(row.at(idx_default_value));
r.extra = row.at(idx_extra).as_blob();
}
Expand All @@ -249,13 +249,13 @@ do_on_abstract_future_execute()
::std::map<cow_string, exIndex> exindexes;

for(uint32_t t = 0; t != fields.size(); ++t)
if(ascii_ci_equal(fields[t], "key_name"))
if(fields[t] == "key_name")
idx_name = t;
else if(ascii_ci_equal(fields[t], "non_unique"))
else if(fields[t] == "non_unique")
idx_non_unique = t;
else if(ascii_ci_equal(fields[t], "column_name"))
else if(fields[t] == "column_name")
idx_column_name = t;
else if(ascii_ci_equal(fields[t], "seq_in_index"))
else if(fields[t] == "seq_in_index")
idx_seq_in_index = t;

while(this->m_conn->fetch_row(row)) {
Expand Down Expand Up @@ -293,10 +293,10 @@ do_on_abstract_future_execute()
case mysql_column_varchar:
{
// The type shall be an exact match.
if(!ascii_ci_equal(ex->second.type, "varchar(255)"))
if(ex->second.type != "varchar(255)")
goto do_alter_table_column_;

if(!column.default_value.is_null()) {
if(column.default_value.is_null() == false) {
// The default value is a string and shall be an exact match of
// the configuration.
if(!ex->second.default_value.is_blob())
Expand All @@ -306,7 +306,7 @@ do_on_abstract_future_execute()
goto do_alter_table_column_;
}

if(!ascii_ci_equal(ex->second.extra, ""))
if(ex->second.extra != "")
goto do_alter_table_column_;
}
break;
Expand All @@ -316,10 +316,10 @@ do_on_abstract_future_execute()
// MySQL does not have a real boolean type, so we use an integer.
// Some old MySQL versions include a display width in the type,
// which is deprecated since 8.0 anyway. Both forms are accepted.
if(!ascii_ci_equal(ex->second.type, "tinyint(1)") && !ascii_ci_equal(ex->second.type, "tinyint"))
if((ex->second.type != "tinyint(1)") && (ex->second.type != "tinyint"))
goto do_alter_table_column_;

if(!column.default_value.is_null()) {
if(column.default_value.is_null() == false) {
// The default value is an integer and shall be an exact match
// of the configuration. The MySQL server returns the default as
// a generic string, so parse it first.
Expand All @@ -335,7 +335,7 @@ do_on_abstract_future_execute()
goto do_alter_table_column_;
}

if(!ascii_ci_equal(ex->second.extra, ""))
if(ex->second.extra != "")
goto do_alter_table_column_;
}
break;
Expand All @@ -344,10 +344,10 @@ do_on_abstract_future_execute()
{
// Some old MySQL versions include a display width in the type,
// which is deprecated since 8.0 anyway. Both forms are accepted.
if(!ascii_ci_equal(ex->second.type, "int(11)") && !ascii_ci_equal(ex->second.type, "int"))
if((ex->second.type != "int(11)") && (ex->second.type != "int"))
goto do_alter_table_column_;

if(!column.default_value.is_null()) {
if(column.default_value.is_null() == false) {
// The default value is an integer and shall be an exact match
// of the configuration. The MySQL server returns the default as
// a generic string, so parse it first.
Expand All @@ -363,7 +363,7 @@ do_on_abstract_future_execute()
goto do_alter_table_column_;
}

if(!ascii_ci_equal(ex->second.extra, ""))
if(ex->second.extra != "")
goto do_alter_table_column_;
}
break;
Expand All @@ -372,10 +372,10 @@ do_on_abstract_future_execute()
{
// Some old MySQL versions include a display width in the type,
// which is deprecated since 8.0 anyway. Both forms are accepted.
if(!ascii_ci_equal(ex->second.type, "bigint(20)") && !ascii_ci_equal(ex->second.type, "bigint"))
if((ex->second.type != "bigint(20)") && (ex->second.type != "bigint"))
goto do_alter_table_column_;

if(!column.default_value.is_null()) {
if(column.default_value.is_null() == false) {
// The default value is an integer and shall be an exact match
// of the configuration. The MySQL server returns the default as
// a generic string, so parse it first.
Expand All @@ -391,18 +391,18 @@ do_on_abstract_future_execute()
goto do_alter_table_column_;
}

if(!ascii_ci_equal(ex->second.extra, ""))
if(ex->second.extra != "")
goto do_alter_table_column_;
}
break;

case mysql_column_double:
{
// The type shall be an exact match.
if(!ascii_ci_equal(ex->second.type, "double"))
if(ex->second.type != "double")
goto do_alter_table_column_;

if(!column.default_value.is_null()) {
if(column.default_value.is_null() == false) {
// The default value is a double and shall be an exact match of
// the configuration. The MySQL server returns the default as a
// generic string, so parse it first.
Expand All @@ -418,7 +418,7 @@ do_on_abstract_future_execute()
goto do_alter_table_column_;
}

if(!ascii_ci_equal(ex->second.extra, ""))
if(ex->second.extra != "")
goto do_alter_table_column_;
}
break;
Expand All @@ -427,21 +427,21 @@ do_on_abstract_future_execute()
{
// The type shall be an exact match. BLOB and TEXT fields cannot
// have a default value, so there is no need to check it.
if(!ascii_ci_equal(ex->second.type, "longblob"))
if(ex->second.type != "longblob")
goto do_alter_table_column_;

if(!ascii_ci_equal(ex->second.extra, ""))
if(ex->second.extra != "")
goto do_alter_table_column_;
}
break;

case mysql_column_datetime:
{
// The type shall be an exact match.
if(!ascii_ci_equal(ex->second.type, "datetime"))
if(ex->second.type != "datetime")
goto do_alter_table_column_;

if(!column.default_value.is_null()) {
if(column.default_value.is_null() == false) {
// The default value is a broken-down date/time and shall be an
// exact match of the configuration. The MySQL server returns
// the default as a generic string, so parse it first.
Expand All @@ -461,7 +461,7 @@ do_on_abstract_future_execute()
goto do_alter_table_column_;
}

if(!ascii_ci_equal(ex->second.extra, ""))
if(ex->second.extra != "")
goto do_alter_table_column_;
}
break;
Expand All @@ -472,10 +472,10 @@ do_on_abstract_future_execute()
// which is deprecated since 8.0 anyway. Both forms are accepted.
// Auto-increment fields cannot have a default value, so there is
// no need to check it.
if(!ascii_ci_equal(ex->second.type, "bigint(20)") && !ascii_ci_equal(ex->second.type, "bigint"))
if((ex->second.type != "bigint(20)") && (ex->second.type != "bigint"))
goto do_alter_table_column_;

if(!ascii_ci_equal(ex->second.extra, "AUTO_INCREMENT"))
if(ex->second.extra != "AUTO_INCREMENT")
goto do_alter_table_column_;
}
break;
Expand Down Expand Up @@ -563,7 +563,7 @@ do_on_abstract_future_execute()
do_append_index_definition(sql, index);
}
else {
if(ascii_ci_equal(index.name, "PRIMARY"))
if(index.name == "PRIMARY")
sql << "DROP PRIMARY KEY";
else
sql << "DROP INDEX `" << index.name << "`";
Expand Down
2 changes: 1 addition & 1 deletion poseidon/http/http_header_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ do_next_attribute_from_separator()
}

sptr += tlen;
this->m_name.swap(this->m_value.mut_string());
this->m_name = move(this->m_value.mut_string());
this->m_value = nullptr;

// If an equals sign is encountered, then there will be a value, so
Expand Down
7 changes: 4 additions & 3 deletions poseidon/http/http_header_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define POSEIDON_HTTP_HTTP_HEADER_PARSER_

#include "../fwd.hpp"
#include "http_field_name.hpp"
#include "http_value.hpp"
namespace poseidon {

Expand All @@ -17,7 +18,7 @@ class HTTP_Header_Parser
size_t m_hpos = 0;

// name and value of current attribute
cow_string m_name;
HTTP_Field_Name m_name;
HTTP_Value m_value;

public:
Expand Down Expand Up @@ -61,11 +62,11 @@ class HTTP_Header_Parser
next_element();

// Get the name of the current attribute.
cow_stringR
const HTTP_Field_Name&
current_name() const noexcept
{ return this->m_name; }

cow_string&
HTTP_Field_Name&
mut_current_name() noexcept
{ return this->m_name; }

Expand Down
6 changes: 3 additions & 3 deletions poseidon/http/http_query_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ next_element()
}

// Accept this sequence.
this->m_name.push_back((char) ch);
this->m_name.mut_str() += (char) ch;
sptr += 3;
continue;
}
Expand All @@ -129,7 +129,7 @@ next_element()
}

// Accpet this character verbatim.
this->m_name.push_back((char) ch);
this->m_name.mut_str() += (char) ch;
sptr ++;
}

Expand All @@ -146,7 +146,7 @@ next_element()
else
this->m_value.mut_string().assign(vstr, vlen);

this->m_name.erase(name_len);
this->m_name.mut_str().erase(name_len);
}

// Accept this name-value pair.
Expand Down
7 changes: 4 additions & 3 deletions poseidon/http/http_query_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define POSEIDON_HTTP_HTTP_QUERY_PARSER_

#include "../fwd.hpp"
#include "http_field_name.hpp"
#include "http_value.hpp"
namespace poseidon {

Expand All @@ -17,7 +18,7 @@ class HTTP_Query_Parser
size_t m_hpos = 0;

// name and value of current element
cow_string m_name;
HTTP_Field_Name m_name;
HTTP_Value m_value;

public:
Expand Down Expand Up @@ -50,11 +51,11 @@ class HTTP_Query_Parser
next_element();

// Get the name of the current element.
cow_stringR
const HTTP_Field_Name&
current_name() const noexcept
{ return this->m_name; }

cow_string&
HTTP_Field_Name&
mut_current_name() noexcept
{ return this->m_name; }

Expand Down
Loading

0 comments on commit 229d8ec

Please sign in to comment.