Skip to content

Commit 490b640

Browse files
committed
Remove ParseWebData dependency and refactor URL parsing
Eliminated usage of ParseWebData and related GCC diagnostic pragmas from http.cpp, http.cpp (webserver), and logic.cpp. Refactored get_first_bible_from_urls to manually parse query parameters, reducing external dependencies and simplifying code. #1047
1 parent 40a1db3 commit 490b640

File tree

3 files changed

+10
-18
lines changed

3 files changed

+10
-18
lines changed

unittests/http.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2727
#include <webserver/http.h>
2828
#include <webserver/request.h>
2929
#include <filter/url.h>
30-
#pragma GCC diagnostic push
31-
#pragma GCC diagnostic ignored "-Weffc++"
32-
#include <parsewebdata/ParseWebData.h>
33-
#pragma GCC diagnostic pop
3430

3531

3632
TEST (http, parse_host)
@@ -215,7 +211,7 @@ TEST (http, parse_post)
215211
}
216212

217213

218-
TEST (http, parse_header) // Todo
214+
TEST (http, parse_header)
219215
{
220216
// Test pstandard GET request.
221217
{

webserver/http.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2121
#include <filter/url.h>
2222
#include <config/globals.h>
2323
#include <filter/string.h>
24-
#pragma GCC diagnostic push
25-
#pragma GCC diagnostic ignored "-Weffc++"
26-
#include <parsewebdata/ParseWebData.h>
27-
#pragma GCC diagnostic pop
2824
#include <webserver/request.h>
2925
#include <database/logs.h>
3026

workspace/logic.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@
3434
#include <database/logs.h>
3535
#include <database/cache.h>
3636
#include <read/index.h>
37-
#pragma GCC diagnostic push
38-
#pragma GCC diagnostic ignored "-Weffc++"
39-
#include <parsewebdata/ParseWebData.h>
40-
#pragma GCC diagnostic pop
4137

4238

4339
std::vector <std::string> workspace_get_default_names ()
@@ -582,18 +578,22 @@ std::map <int, int> workspace_add_bible_editor_number (std::map <int, std::strin
582578
}
583579

584580

581+
582+
// Input: List of URLs like this: /a/b?bible=1&topbar=0
585583
std::optional<std::string> get_first_bible_from_urls (const std::map <int,std::string>& urls)
586584
{
587585
for (const auto& [key, url] : urls) {
588586
const std::vector <std::string> bits = filter::strings::explode (url, '?');
589587
if (bits.size() != 2)
590588
continue;
591589
if (!bits.at(1).empty ()) {
592-
ParseWebData::WebDataMap web_data_map;
593-
ParseWebData::parse_get_data (bits.at(1), web_data_map);
594-
for (auto iter = web_data_map.cbegin(); iter != web_data_map.cend(); ++iter) {
595-
if ((*iter).first == "bible")
596-
return filter_url_urldecode ((*iter).second.value);
590+
// Explode the data on the ampersand ( & ) and then on the equal sign ( = ).
591+
std::vector<std::string> keys_values = filter::strings::explode(bits.at(1), '&');
592+
for (const auto& fragment : keys_values) {
593+
std::vector<std::string> key_value = filter::strings::explode(fragment, '=');
594+
if (key_value.size() == 2)
595+
if (key_value.at(0) == "bible")
596+
return filter_url_urldecode (key_value.at(1));
597597
}
598598
}
599599
}

0 commit comments

Comments
 (0)