Skip to content

Commit

Permalink
hotplace rev.493 http2 study - frame
Browse files Browse the repository at this point in the history
  • Loading branch information
princeb612 committed Apr 16, 2024
1 parent c660b74 commit 0519ce6
Show file tree
Hide file tree
Showing 21 changed files with 1,351 additions and 109 deletions.
91 changes: 91 additions & 0 deletions sdk/io/string/regex.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/* vim: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab smarttab : */
/**
* @file {file}
* @author Soo Han, Kim (princeb612.kr@gmail.com)
* @desc
*
* Revision History
* Date Name Description
*/

#include <regex>
#include <sdk/base/basic/base16.hpp>
#include <sdk/io/string/string.hpp>
#if (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)) || (__GNUC__ > 4))
#else
#include <pcre.h>
#endif

namespace hotplace {
namespace io {

void regex_token(std::string const& input, std::string const& expr, size_t& pos, std::list<std::string>& tokens) {
tokens.clear();

#if (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)) || (__GNUC__ > 4))
// Regular expressions library (since C++11) https://en.cppreference.com/w/cpp/regex
// The GNU C++ standard library supports <regex>, but not until GCC version 4.9.0.
// undefined reference to re_expr/sregex_iterator/smatch in GCC 4.8.5 (fixed in GCC 4.9.0)

std::regex re_expr(expr);
auto re_begin = std::sregex_iterator(input.begin() + pos, input.end(), re_expr);
auto re_end = std::sregex_iterator();

// size_t count = std::distance(re_begin, re_end);

for (std::sregex_iterator i = re_begin; i != re_end; ++i) {
std::smatch match = *i;
std::string token = match.str();
if (token.size()) {
tokens.push_back(token);
pos += (match.position() + match.str().size());
}
}
#else
pcre* re = nullptr;
int rc = 0;
int eoffset = 0;
const char* err = nullptr;
const char* sub = nullptr;

std::vector<int> ovector;
ovector.resize(30);

__try2 {
re = pcre_compile(expr.c_str(), 0, &err, &eoffset, nullptr);
if (nullptr == re) {
__leave2;
}

while (1) {
const char* subj = input.c_str() + pos;
size_t subjlen = input.size() - pos;

rc = pcre_exec(re, nullptr, subj, subjlen, 0, PCRE_NOTEMPTY, &ovector[0], ovector.size());

if (PCRE_ERROR_NOMATCH == rc) {
break;
} else if (rc < -1) {
break;
} else {
for (int i = 0; i < rc; i++) {
pcre_get_substring(subj, &ovector[0], rc, i, &sub);
if (sub) {
tokens.push_back(sub);
pos += ovector[i + 1];
pcre_free_substring(sub);
}
}
}
}
}
__finally2 {
if (re) {
pcre_free(re);
}
}
#endif
}

} // namespace io
} // namespace hotplace
9 changes: 9 additions & 0 deletions sdk/io/string/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ return_t scan(const wchar_t* stream, size_t sizestream, size_t startpos, size_t*
//
// std::regex
//

/**
* @brief regular expression
* @param std::string const& input [in]
* @param std::string const& expr [in]
* @param size_t& pos [out]
* @param std::list<std::string>& tokens [out]
* @sa split_url
*/
void regex_token(std::string const& input, std::string const& expr, size_t& pos, std::list<std::string>& tokens);

/**
Expand Down
68 changes: 0 additions & 68 deletions sdk/io/string/url.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,74 +19,6 @@
namespace hotplace {
namespace io {

void regex_token(std::string const& input, std::string const& expr, size_t& pos, std::list<std::string>& tokens) {
tokens.clear();

#if (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)) || (__GNUC__ > 4))
// Regular expressions library (since C++11) https://en.cppreference.com/w/cpp/regex
// The GNU C++ standard library supports <regex>, but not until GCC version 4.9.0.
// undefined reference to re_expr/sregex_iterator/smatch in GCC 4.8.5 (fixed in GCC 4.9.0)

std::regex re_expr(expr);
auto re_begin = std::sregex_iterator(input.begin() + pos, input.end(), re_expr);
auto re_end = std::sregex_iterator();

// size_t count = std::distance(re_begin, re_end);

for (std::sregex_iterator i = re_begin; i != re_end; ++i) {
std::smatch match = *i;
std::string token = match.str();
if (token.size()) {
tokens.push_back(token);
pos += (match.position() + match.str().size());
}
}
#else
pcre* re = nullptr;
int rc = 0;
int eoffset = 0;
const char* err = nullptr;
const char* sub = nullptr;

std::vector<int> ovector;
ovector.resize(30);

__try2 {
re = pcre_compile(expr.c_str(), 0, &err, &eoffset, nullptr);
if (nullptr == re) {
__leave2;
}

while (1) {
const char* subj = input.c_str() + pos;
size_t subjlen = input.size() - pos;

rc = pcre_exec(re, nullptr, subj, subjlen, 0, PCRE_NOTEMPTY, &ovector[0], ovector.size());

if (PCRE_ERROR_NOMATCH == rc) {
break;
} else if (rc < -1) {
break;
} else {
for (int i = 0; i < rc; i++) {
pcre_get_substring(subj, &ovector[0], rc, i, &sub);
if (sub) {
tokens.push_back(sub);
pos += ovector[i + 1];
pcre_free_substring(sub);
}
}
}
}
}
__finally2 {
if (re) {
pcre_free(re);
}
}
#endif
}

return_t escape_url(const char* url, stream_t* s, uint32 flags) {
return_t ret = errorcode_t::success;
__try2 {
Expand Down
1 change: 1 addition & 0 deletions sdk/net.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <sdk/net/http/bearer_authentication_provider.hpp>
#include <sdk/net/http/digest_access_authentication_provider.hpp>
#include <sdk/net/http/html_documents.hpp>
#include <sdk/net/http/http2_protocol.hpp>
#include <sdk/net/http/http_authentication_provider.hpp>
#include <sdk/net/http/http_authentication_resolver.hpp>
#include <sdk/net/http/http_client.hpp>
Expand Down
24 changes: 0 additions & 24 deletions sdk/net/http/http2.cpp

This file was deleted.

Loading

0 comments on commit 0519ce6

Please sign in to comment.