Skip to content

Commit f966c2d

Browse files
committed
- rename url_payload to click_payload
- leave only single url field in click_payload to avoid a lot of confustion!
1 parent 5943417 commit f966c2d

29 files changed

+127
-177
lines changed

bt/app/browser.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ namespace bt {
101101

102102
std::vector<browser_match_result> browser::match(
103103
const std::vector<shared_ptr<browser>>& browsers,
104-
const url_payload& up,
104+
const click_payload& up,
105105
const string& default_profile_long_id) {
106106
vector<browser_match_result> r;
107107

@@ -245,8 +245,8 @@ namespace bt {
245245

246246
browser_instance::~browser_instance() {}
247247

248-
void browser_instance::launch(url_payload up) const {
249-
string url = up.open_url.empty() ? up.url : up.open_url;
248+
void browser_instance::launch(click_payload up) const {
249+
string url = up.url;
250250
string arg = launch_arg;
251251

252252
if(arg.empty()) {
@@ -279,7 +279,7 @@ namespace bt {
279279
}
280280
}
281281

282-
bool browser_instance::is_match(const url_payload& up, match_rule& mr) const {
282+
bool browser_instance::is_match(const click_payload& up, match_rule& mr) const {
283283
for (const auto& rule : rules) {
284284
if (rule->is_match(up)) {
285285
mr = *rule;

bt/app/browser.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <vector>
44
#include <memory>
55
#include "match_rule.h"
6-
#include "url_payload.h"
6+
#include "click_payload.h"
77

88
namespace bt {
99

@@ -83,7 +83,7 @@ namespace bt {
8383

8484
static std::vector<browser_match_result> match(
8585
const std::vector<std::shared_ptr<browser>>& browsers,
86-
const url_payload& up,
86+
const click_payload& up,
8787
const std::string& default_profile_long_id);
8888

8989
static std::shared_ptr<browser_instance> get_default(
@@ -123,9 +123,9 @@ namespace bt {
123123

124124
~browser_instance();
125125

126-
void launch(url_payload up) const;
126+
void launch(click_payload up) const;
127127

128-
bool is_match(const url_payload& up, match_rule& mr) const;
128+
bool is_match(const click_payload& up, match_rule& mr) const;
129129

130130
/// <summary>
131131
/// Adds a rule from text. Does not persist.

bt/app/url_payload.h bt/app/click_payload.h

+2-8
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
#endif
66

77
namespace bt {
8-
struct url_payload {
9-
std::string url; // very first, raw input URL
8+
struct click_payload {
9+
std::string url;
1010

1111
bool app_mode{false};
1212

@@ -20,10 +20,6 @@ namespace bt {
2020
std::string window_title;
2121
std::string process_name;
2222

23-
// the URLs below are optional, and if populated, extra handling is possible
24-
std::string match_url; // URL to match on
25-
std::string open_url; // final URL to open
26-
2723
bool empty() const {
2824
return url.empty() && window_title.empty() && process_name.empty();
2925
}
@@ -34,8 +30,6 @@ namespace bt {
3430
}
3531
window_title.clear();
3632
process_name.clear();
37-
match_url.clear();
38-
open_url.clear();
3933
}
4034
};
4135
}

bt/app/match_rule.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,14 @@ namespace bt {
196196
}
197197
}
198198

199-
bool match_rule::is_match(const url_payload& up) const {
199+
bool match_rule::is_match(const click_payload& up) const {
200200

201201
if(value.empty()) return false;
202202

203203
string src;
204204
switch(loc) {
205205
case match_location::url:
206-
src = up.match_url;
206+
src = up.url;
207207
break;
208208
case match_location::window_title:
209209
src = up.window_title;
@@ -245,8 +245,7 @@ namespace bt {
245245
}
246246

247247
bool match_rule::is_match(const string& url) const {
248-
url_payload up{url};
249-
up.match_url = url;
248+
click_payload up{url};
250249
return is_match(up);
251250
}
252251
}

bt/app/match_rule.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <string>
44
#include <vector>
5-
#include "url_payload.h"
5+
#include "click_payload.h"
66

77
namespace bt {
88
enum class match_scope : size_t {
@@ -21,7 +21,7 @@ namespace bt {
2121
public:
2222
explicit match_rule(const std::string& line);
2323

24-
bool is_match(const url_payload& up) const;
24+
bool is_match(const click_payload& up) const;
2525
bool is_match(const std::string& url) const;
2626

2727
std::string value;

bt/app/pipeline/o365.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@
55
using namespace std;
66

77
namespace bt::pipeline {
8-
void o365::process(url_payload& up) {
8+
void o365::process(click_payload& up) {
99
url u{up.url};
1010

1111
if(u.host.ends_with(".safelinks.protection.outlook.com")) {
1212
for(const auto& p : u.parameters) {
1313
if(p.first == "url") {
1414
string url = p.second;
15-
url = str::url_decode(url);
16-
up.match_url = url;
17-
up.open_url = up.url;
15+
up.url = str::url_decode(url);
1816
}
1917
}
2018
}

bt/app/pipeline/o365.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ namespace bt::pipeline {
88
o365() : url_pipeline_step(url_pipeline_step_type::o365) {}
99

1010
// Inherited via url_pipeline_step
11-
void process(url_payload& up) override;
11+
void process(click_payload& up) override;
1212
};
1313
}

bt/app/pipeline/replacer.cpp

+5-8
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,17 @@ namespace bt::pipeline {
3636
replace});
3737
}
3838

39-
void replacer::process(url_payload& up) {
40-
string url = up.match_url.empty() ? up.url : up.match_url;
41-
39+
void replacer::process(click_payload& up) {
4240
if(kind == replacer_kind::find_replace) {
43-
size_t idx = url.find(find);
41+
size_t idx = up.url.find(find);
4442
if(idx != string::npos) {
45-
str::replace_all(url, find, replace);
46-
up.match_url = up.open_url = url;
43+
str::replace_all(up.url, find, replace);
4744
}
4845
} else {
4946
// regex
5047
regex rgx{find, regex_constants::icase};
51-
if(regex_search(url, rgx)) {
52-
up.match_url = up.open_url = regex_replace(url, rgx, replace);
48+
if(regex_search(up.url, rgx)) {
49+
up.url = regex_replace(up.url, rgx, replace);
5350
}
5451
}
5552
}

bt/app/pipeline/replacer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace bt::pipeline {
2323
std::string serialise();
2424

2525
// Inherited via url_pipeline_step
26-
void process(url_payload& up) override;
26+
void process(click_payload& up) override;
2727

2828
private:
2929
};

bt/app/pipeline/unshortener.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,19 @@ namespace bt::pipeline {
2727
"vrch.at"
2828
};
2929

30-
void unshortener::process(url_payload& up) {
30+
void unshortener::process(click_payload& up) {
3131

32-
string url = up.match_url.empty() ? up.url : up.match_url;
33-
34-
if(!is_supported(url)) return;
32+
if(!is_supported(up.url)) return;
3533

3634
// example: https://bit.ly/47EZHSl -> https://github.com/aloneguid/bt
3735

3836
map<string, string> headers;
39-
int code = http.get_get_headers(url, headers);
37+
int code = http.get_get_headers(up.url, headers);
4038

4139
map<string, string>::const_iterator it_loc;
4240
if((code == 301 || code == 302) && (it_loc = headers.find(LocationHeaderName)) != headers.end()) {
4341
string new_url = it_loc->second;
44-
up.match_url = up.open_url = new_url;
42+
up.url = new_url;
4543
}
4644
}
4745

bt/app/pipeline/unshortener.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace bt::pipeline {
99
unshortener() : url_pipeline_step(url_pipeline_step_type::unshortener) {}
1010

1111
// Inherited via url_pipeline_step
12-
void process(url_payload& up) override;
12+
void process(click_payload& up) override;
1313

1414
private:
1515
win32::http http;

bt/app/rule_hit_log.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace bt {
2626
"browser_name",
2727
"profile_name",
2828
"url",
29-
"match_url",
29+
"n/a",
3030
"open_url",
3131
"rule",
3232
"calling_process_name",
@@ -36,15 +36,15 @@ namespace bt {
3636
}
3737
}
3838

39-
void rule_hit_log::write(const bt::url_payload& up, std::shared_ptr<bt::browser_instance> bi, const std::string& rule) {
39+
void rule_hit_log::write(const bt::click_payload& up, std::shared_ptr<bt::browser_instance> bi, const std::string& rule) {
4040
writer.write_row(vector<string>{
4141
datetime::to_iso_8601(),
4242
bi->b->id,
4343
bi->b->name,
4444
bi->name,
4545
up.url,
46-
up.match_url,
47-
up.open_url,
46+
"",
47+
up.url,
4848
rule,
4949
up.process_name,
5050
up.window_title

bt/app/rule_hit_log.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace bt {
88
public:
99
rule_hit_log();
1010

11-
void write(const bt::url_payload& up, std::shared_ptr<bt::browser_instance> bi, const std::string& rule);
11+
void write(const bt::click_payload& up, std::shared_ptr<bt::browser_instance> bi, const std::string& rule);
1212

1313
std::string get_absolute_path() { return path; }
1414

bt/app/script_site.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ namespace bt {
6565
reload();
6666
}
6767

68-
bool script_site::call_rule(url_payload& up, const string& function_name) {
68+
bool script_site::call_rule(click_payload& up, const string& function_name) {
6969

7070
// set global table "p" with 3 members: url, window_title, process_name
7171
lua_newtable(L);
72-
lua_pushstring(L, up.match_url.c_str());
72+
lua_pushstring(L, up.url.c_str());
7373
lua_setfield(L, -2, "url");
7474
lua_pushstring(L, up.window_title.c_str());
7575
lua_setfield(L, -2, "wt");

bt/app/script_site.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22
#include "lua.hpp"
33
#include <string>
4-
#include "url_payload.h"
4+
#include "click_payload.h"
55

66
namespace bt {
77
class script_site {
@@ -19,7 +19,7 @@ namespace bt {
1919
void set_code(const std::string& code);
2020

2121
// bt specific functions
22-
bool call_rule(url_payload& up, const std::string& function_name);
22+
bool call_rule(click_payload& up, const std::string& function_name);
2323

2424

2525
private:

0 commit comments

Comments
 (0)